store as system contract in erigon db#4700
Conversation
| if len(ret) < 4 { | ||
| return hex.EncodeToString(ret) | ||
| } | ||
| if !bytes.Equal(ret[:4], _revertSelector) { | ||
| return hex.EncodeToString(ret) | ||
| } |
| for (uint256 i = 0; i < keys.length; i++) { | ||
| if (keccak256(keys[i]) == keccak256(key)) { | ||
| // Move last element to current position and pop | ||
| keys[i] = keys[keys.length - 1]; | ||
| keys.pop(); | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
we may have efficiency problem here
| bytes auxiliaryData; // Additional data field for flexibility | ||
| } | ||
|
|
||
| // Nested mapping: namespace => key => value |
There was a problem hiding this comment.
keyMap: namespace => key => index (start from 1)
keys: namespace => []bytes
values: namespace => []bytes
Delete: if index is not 0, delete it from map, update the keys and values
There was a problem hiding this comment.
not sure in the KeyMap, we should store hash(namespace), hash(key) or the raw data.
| uint256 index = keyIndex_[key] - 1; | ||
| values_[index] = value; |
There was a problem hiding this comment.
values_[keyIndex_[key] - 1] = value;
| bytes memory lastKey = keys_[lastIndex]; | ||
| GenericValue memory lastValue = values_[lastIndex]; |
c102388 to
791c488
Compare
| func (store *stateDBWorkingSetStore) PutObject(ns string, key []byte, obj any) error { | ||
| store.lock.Lock() | ||
| defer store.lock.Unlock() | ||
| value, err := state.Serialize(obj) | ||
| if err != nil { | ||
| return errors.Wrapf(err, "failed to serialize object of ns = %x and key = %x", ns, key) | ||
| } | ||
| return store.putKV(ns, key, value) | ||
| } | ||
|
|
||
| func (store *stateDBWorkingSetStore) Put(ns string, key []byte, value []byte) error { | ||
| store.lock.Lock() | ||
| defer store.lock.Unlock() | ||
| return store.putKV(ns, key, value) | ||
| } | ||
|
|
There was a problem hiding this comment.
can we merge them? e.g.,
Put(ns string, key []byte, value any) error {
switch v := value.(type) {
case []byte:
...
default:
...
}
| ) | ||
|
|
||
| type ( | ||
| contractBacked struct { |
| } | ||
| ) | ||
|
|
||
| func NewContractBackend(intraBlockState *erigonstate.IntraBlockState, org erigonstate.StateReader, height uint64, timestamp time.Time, g *genesis.Genesis, evmNetworkID uint32) *contractBacked { |
| return nil, errors.Errorf("unknown account type %v for address %x", pbAcc.Type, addr.Bytes()) | ||
| } | ||
|
|
||
| if ch := backend.intraBlockState.GetCodeHash(addr); !accounts.IsEmptyCodeHash(ch) { |
| ) | ||
| return | ||
| }, | ||
| Coinbase: erigonComm.Address{}, |
| contract, err := cs.storageContract(ns, nil, backend) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } |
There was a problem hiding this comment.
if the second parameter key could be nil, could it be deleted?
https://github.com/iotexproject/iotex-core/pull/4713/files#diff-9da80c318e8632df1ada1dfb8591fde58e2a5d552dff50190cb8bae9be185538R105
https://github.com/iotexproject/iotex-core/pull/4713/files#diff-ab7c631037f77fb2370b048394c3e86dcdfa2cfeab04ea6d75a86894591ca510R236
https://github.com/iotexproject/iotex-core/pull/4713/files#diff-f8f5e54d3315e09e8fb916f754667e46a305e9a143b8f70dd7b39110e68590d0R87-R95
https://github.com/iotexproject/iotex-core/pull/4713/files#diff-f8f5e54d3315e09e8fb916f754667e46a305e9a143b8f70dd7b39110e68590d0R144-R151
according to the implementations in the follow up PRs, key could be deleted.
| ctx = genesis.WithGenesisContext(ctx, *backend.g) | ||
| ctx = protocol.WithBlockchainCtx(ctx, protocol.BlockchainCtx{ | ||
| GetBlockTime: func(u uint64) (time.Time, error) { | ||
| interval := 2500 * time.Millisecond |
There was a problem hiding this comment.
cannot hardcode the block interval in this way.
| if ns == "" { | ||
| return nil, errors.New("namespace cannot be empty") | ||
| } |
|


Description
The erigon database, in addition to storing account and contract data, now also supports storing data that satisfies the ContractStorage interface in the form of system contracts in erigon.
The main changes are as follows:
base #4699
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: