Skip to content

[statedb] store account by erigon #4559

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

Merged
merged 12 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func blockHeightToTime(ctx context.Context, height uint64) (*time.Time, error) {
if height == blkCtx.BlockHeight {
return &blkCtx.BlockTimeStamp, nil
}
t, err := mustGetHelperCtx(ctx).GetBlockTime(height)
t, err := protocol.MustGetBlockchainCtx(ctx).GetBlockTime(height)
if err != nil {
return nil, err
}
Expand Down
12 changes: 8 additions & 4 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ func TestConstantinople(t *testing.T) {

evmNetworkID := uint32(100)
g := genesis.TestDefault()
now := time.Now()
getBlockTime := func(height uint64) (time.Time, error) {
return now.Add(time.Duration(height) * time.Second * 5), nil
}
ctx = protocol.WithBlockchainCtx(genesis.WithGenesisContext(ctx, g), protocol.BlockchainCtx{
ChainID: 1,
EvmNetworkID: evmNetworkID,
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
GetBlockTime: getBlockTime,
})

execHeights := []struct {
Expand Down Expand Up @@ -281,10 +289,6 @@ func TestConstantinople(t *testing.T) {
1261440000, // = 200*365*24*3600/5, around 200 years later
},
}
now := time.Now()
getBlockTime := func(height uint64) (time.Time, error) {
return now.Add(time.Duration(height) * time.Second * 5), nil
}
for _, e := range execHeights {
ex := action.NewExecution(e.contract, big.NewInt(0), nil)
elp := (&action.EnvelopeBuilder{}).SetNonce(1).SetGasPrice(big.NewInt(10)).
Expand Down
11 changes: 9 additions & 2 deletions action/protocol/execution/evm/evmstatedbadapter_erigon.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evm

import (
"context"
"time"

erigonchain "github.com/erigontech/erigon-lib/chain"
Expand All @@ -14,6 +15,7 @@ import (

"github.com/iotexproject/go-pkgs/hash"

"github.com/iotexproject/iotex-core/v2/action/protocol"
"github.com/iotexproject/iotex-core/v2/blockchain/genesis"
"github.com/iotexproject/iotex-core/v2/pkg/log"
"github.com/iotexproject/iotex-core/v2/state"
Expand Down Expand Up @@ -222,6 +224,11 @@ func NewErigonRules(rules *params.Rules) *erigonchain.Rules {
}

// NewChainConfig creates a new chain config
func NewChainConfig(g genesis.Blockchain, height uint64, id uint32, getBlockTime func(uint64) (*time.Time, error)) (*params.ChainConfig, error) {
return getChainConfig(g, height, id, getBlockTime)
func NewChainConfig(ctx context.Context) (*params.ChainConfig, error) {
blkCtx := protocol.MustGetBlockCtx(ctx)
g := genesis.MustExtractGenesisContext(ctx)
bcCtx := protocol.MustGetBlockchainCtx(ctx)
return getChainConfig(g.Blockchain, blkCtx.BlockHeight, bcCtx.EvmNetworkID, func(height uint64) (*time.Time, error) {
return blockHeightToTime(ctx, height)
})
}
1 change: 1 addition & 0 deletions blockchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type (
ContractStakingIndexDBPath string `yaml:"contractStakingIndexDBPath"`
BlobStoreDBPath string `yaml:"blobStoreDBPath"`
BlobStoreRetentionDays uint32 `yaml:"blobStoreRetentionDays"`
HistoryIndexPath string `yaml:"historyIndexPath"`
ID uint32 `yaml:"id"`
EVMNetworkID uint32 `yaml:"evmNetworkID"`
Address string `yaml:"address"`
Expand Down
Loading