Skip to content
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

get forkid dirrectly by block #1116

Merged
merged 2 commits into from
Sep 5, 2024
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
9 changes: 2 additions & 7 deletions zk/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func ShouldShortCircuitExecution(tx kv.RwTx, logPrefix string) (bool, uint64, er
}

type ForkReader interface {
GetLowestBatchByFork(forkId uint64) (uint64, error)
GetLowestBlockInBatch(batchNo uint64) (blockNo uint64, found bool, err error)
GetForkIdBlock(forkId uint64) (uint64, bool, error)
}

type ForkConfigWriter interface {
Expand All @@ -95,11 +94,7 @@ func UpdateZkEVMBlockCfg(cfg ForkConfigWriter, hermezDb ForkReader, logPrefix st
var foundAny bool = false

for _, forkId := range chain.ForkIdsOrdered {
batch, err := hermezDb.GetLowestBatchByFork(uint64(forkId))
if err != nil {
return err
}
blockNum, found, err := hermezDb.GetLowestBlockInBatch(batch)
blockNum, found, err := hermezDb.GetForkIdBlock(uint64(forkId))
if err != nil {
return err
}
Expand Down
36 changes: 9 additions & 27 deletions zk/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@ package utils
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/ledgerwatch/erigon/zk/constants"
"github.com/stretchr/testify/assert"
)

type SimpleForkReader struct {
BatchForks map[constants.ForkId]uint64
LowestBlocks map[uint64]uint64
}

func (s *SimpleForkReader) GetLowestBatchByFork(forkId uint64) (uint64, error) {
found, _ := s.BatchForks[constants.ForkId(forkId)]
return found, nil
BlockForks map[constants.ForkId]uint64
}

func (s *SimpleForkReader) GetLowestBlockInBatch(batchNo uint64) (uint64, bool, error) {
found, ok := s.LowestBlocks[batchNo]
func (s *SimpleForkReader) GetForkIdBlock(forkId uint64) (uint64, bool, error) {
found, ok := s.BlockForks[constants.ForkId(forkId)]
return found, ok, nil
}

Expand All @@ -39,21 +33,17 @@ func (tc *TestConfig) SetForkIdBlock(forkId constants.ForkId, blockNum uint64) e

type testScenario struct {
name string
batchForks map[constants.ForkId]uint64
lowestBlocks map[uint64]uint64
blockForks map[constants.ForkId]uint64
expectedCalls map[constants.ForkId]uint64
}

func TestUpdateZkEVMBlockCfg(t *testing.T) {
scenarios := []testScenario{
{
name: "HigherForkEnabled",
batchForks: map[constants.ForkId]uint64{
blockForks: map[constants.ForkId]uint64{
constants.ForkID9Elderberry2: 900,
},
lowestBlocks: map[uint64]uint64{
900: 900,
},
expectedCalls: map[constants.ForkId]uint64{
constants.ForkID9Elderberry2: 900,
constants.ForkID8Elderberry: 900,
Expand All @@ -65,14 +55,10 @@ func TestUpdateZkEVMBlockCfg(t *testing.T) {
},
{
name: "MiddleForksExplicitlyEnabled",
batchForks: map[constants.ForkId]uint64{
blockForks: map[constants.ForkId]uint64{
constants.ForkID7Etrog: 700,
constants.ForkID6IncaBerry: 600,
},
lowestBlocks: map[uint64]uint64{
700: 700,
600: 600,
},
expectedCalls: map[constants.ForkId]uint64{
constants.ForkID7Etrog: 700,
constants.ForkID6IncaBerry: 600,
Expand All @@ -82,14 +68,10 @@ func TestUpdateZkEVMBlockCfg(t *testing.T) {
},
{
name: "MissingEnablements",
batchForks: map[constants.ForkId]uint64{
blockForks: map[constants.ForkId]uint64{
constants.ForkID4: 100,
constants.ForkID6IncaBerry: 600,
},
lowestBlocks: map[uint64]uint64{
100: 100,
600: 600,
},
expectedCalls: map[constants.ForkId]uint64{
constants.ForkID6IncaBerry: 600,
constants.ForkID5Dragonfruit: 600,
Expand All @@ -101,7 +83,7 @@ func TestUpdateZkEVMBlockCfg(t *testing.T) {
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
cfg := NewTestConfig()
reader := &SimpleForkReader{BatchForks: scenario.batchForks, LowestBlocks: scenario.lowestBlocks}
reader := &SimpleForkReader{BlockForks: scenario.blockForks}

err := UpdateZkEVMBlockCfg(cfg, reader, "TestPrefix")
assert.NoError(t, err, "should not return an error")
Expand Down
Loading