Skip to content

Commit 21c7b2d

Browse files
authored
[statedb] store account by erigon (#4559)
1 parent 62bb978 commit 21c7b2d

15 files changed

+1253
-32
lines changed

action/protocol/execution/evm/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func blockHeightToTime(ctx context.Context, height uint64) (*time.Time, error) {
464464
if height == blkCtx.BlockHeight {
465465
return &blkCtx.BlockTimeStamp, nil
466466
}
467-
t, err := mustGetHelperCtx(ctx).GetBlockTime(height)
467+
t, err := protocol.MustGetBlockchainCtx(ctx).GetBlockTime(height)
468468
if err != nil {
469469
return nil, err
470470
}

action/protocol/execution/evm/evm_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,17 @@ func TestConstantinople(t *testing.T) {
8282

8383
evmNetworkID := uint32(100)
8484
g := genesis.TestDefault()
85+
now := time.Now()
86+
getBlockTime := func(height uint64) (time.Time, error) {
87+
return now.Add(time.Duration(height) * time.Second * 5), nil
88+
}
8589
ctx = protocol.WithBlockchainCtx(genesis.WithGenesisContext(ctx, g), protocol.BlockchainCtx{
8690
ChainID: 1,
8791
EvmNetworkID: evmNetworkID,
92+
GetBlockHash: func(uint64) (hash.Hash256, error) {
93+
return hash.ZeroHash256, nil
94+
},
95+
GetBlockTime: getBlockTime,
8896
})
8997

9098
execHeights := []struct {
@@ -281,10 +289,6 @@ func TestConstantinople(t *testing.T) {
281289
1261440000, // = 200*365*24*3600/5, around 200 years later
282290
},
283291
}
284-
now := time.Now()
285-
getBlockTime := func(height uint64) (time.Time, error) {
286-
return now.Add(time.Duration(height) * time.Second * 5), nil
287-
}
288292
for _, e := range execHeights {
289293
ex := action.NewExecution(e.contract, big.NewInt(0), nil)
290294
elp := (&action.EnvelopeBuilder{}).SetNonce(1).SetGasPrice(big.NewInt(10)).

action/protocol/execution/evm/evmstatedbadapter_erigon.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package evm
22

33
import (
4+
"context"
45
"time"
56

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

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

18+
"github.com/iotexproject/iotex-core/v2/action/protocol"
1719
"github.com/iotexproject/iotex-core/v2/blockchain/genesis"
1820
"github.com/iotexproject/iotex-core/v2/pkg/log"
1921
"github.com/iotexproject/iotex-core/v2/state"
@@ -222,6 +224,11 @@ func NewErigonRules(rules *params.Rules) *erigonchain.Rules {
222224
}
223225

224226
// NewChainConfig creates a new chain config
225-
func NewChainConfig(g genesis.Blockchain, height uint64, id uint32, getBlockTime func(uint64) (*time.Time, error)) (*params.ChainConfig, error) {
226-
return getChainConfig(g, height, id, getBlockTime)
227+
func NewChainConfig(ctx context.Context) (*params.ChainConfig, error) {
228+
blkCtx := protocol.MustGetBlockCtx(ctx)
229+
g := genesis.MustExtractGenesisContext(ctx)
230+
bcCtx := protocol.MustGetBlockchainCtx(ctx)
231+
return getChainConfig(g.Blockchain, blkCtx.BlockHeight, bcCtx.EvmNetworkID, func(height uint64) (*time.Time, error) {
232+
return blockHeightToTime(ctx, height)
233+
})
227234
}

blockchain/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type (
3838
ContractStakingIndexDBPath string `yaml:"contractStakingIndexDBPath"`
3939
BlobStoreDBPath string `yaml:"blobStoreDBPath"`
4040
BlobStoreRetentionDays uint32 `yaml:"blobStoreRetentionDays"`
41+
HistoryIndexPath string `yaml:"historyIndexPath"`
4142
ID uint32 `yaml:"id"`
4243
EVMNetworkID uint32 `yaml:"evmNetworkID"`
4344
Address string `yaml:"address"`

0 commit comments

Comments
 (0)