-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/runtime: implement ext_local_storage_set and ext_local_storage_get #1101
Conversation
lib/runtime/storage.go
Outdated
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might make more sense to have this in the dot/state
package, since that's where all the database related functionality is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I move this to dot/state
I get an import cycle, any suggestions?
package github.com/ChainSafe/gossamer/lib/runtime
imports github.com/ChainSafe/gossamer/dot/state
imports github.com/ChainSafe/gossamer/lib/genesis
imports github.com/ChainSafe/gossamer/lib/runtime: import cycle not allowed
lib/runtime/storage.go
Outdated
// NewNodeStorageDB instantiates badgerDB instance for storing runtime persistent data | ||
func NewNodeStorageDB(db chaindb.Database) *NodeStorageDB { | ||
return &NodeStorageDB{ | ||
db, | ||
} | ||
} | ||
|
||
// Put appends `storage` to the key and sets the key-value pair in the db | ||
func (storageDB *NodeStorageDB) Put(key, value []byte) error { | ||
key = append(storagePrefix, key...) | ||
return storageDB.db.Put(key, value) | ||
} | ||
|
||
// Get appends `storage` to the key and retrieves the value from the db | ||
func (storageDB *NodeStorageDB) Get(key []byte) ([]byte, error) { | ||
key = append(storagePrefix, key...) | ||
return storageDB.db.Get(key) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to use table
to add the prefixes instead of doing it manually, see #1091
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good! please clean up todos and move database functionality to dot/state
This is ready for a re-review. |
lib/runtime/runtime.go
Outdated
@@ -29,21 +29,35 @@ import ( | |||
var memory, memErr = wasm.NewMemory(17, 0) | |||
var logger = log.New("pkg", "runtime") | |||
|
|||
// NodeStorageTypePersistent flog to identify offchain storage as persistent (db) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work :)
Changes
BasicStorage
interface andNodeStorage
struct to use for runtime offchain worker storage.ext_local_storage_set
andext_local_storage_get
functionsTests
Checklist
Issues