Skip to content

Commit

Permalink
Merge branch 'develop' into c/improved_error_logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cabrador authored Oct 8, 2024
2 parents be78d94 + 4add44c commit 8464f54
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 122 deletions.
4 changes: 2 additions & 2 deletions cmd/aida-vm-sdb/run_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func runEth(
extensionList,
logger.MakeEthStateTestLogger(cfg, 0),
validator.MakeShadowDbValidator(cfg),
statedb.MakeEthStateScopeTestEventEmitter(),
validator.MakeEthStateTestValidator(cfg),
statedb.MakeEthStateScopeTestEventEmitter(),
)

extensionList = append(extensionList, extra...)
Expand All @@ -139,7 +139,7 @@ func runEth(
To: int(cfg.Last) + 1,
NumWorkers: 1,
State: stateDb,
ParallelismGranularity: executor.TransactionLevel,
ParallelismGranularity: executor.BlockLevel,
},
processor,
extensionList,
Expand Down
82 changes: 44 additions & 38 deletions cmd/aida-vm-sdb/run_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,36 @@ func TestVmSdb_Eth_AllDbEventsAreIssuedInOrder(t *testing.T) {
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 2, Transaction: 1, Data: data})
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 2, Transaction: 2, Data: data})
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 2, Transaction: 0, Data: data})
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 3, Transaction: 1, Data: data})
return nil
})

gomock.InOrder(
// Tx 1
db.EXPECT().BeginBlock(uint64(2)),
db.EXPECT().BeginTransaction(uint32(1)),
db.EXPECT().SetTxContext(gomock.Any(), 1),
db.EXPECT().BeginTransaction(uint32(0)),
db.EXPECT().SetTxContext(gomock.Any(), 0),
db.EXPECT().Snapshot().Return(15),
db.EXPECT().GetNonce(data.GetMessage().From).Return(uint64(1)),
db.EXPECT().GetCodeHash(data.GetMessage().From).Return(common.HexToHash("0x0")),
db.EXPECT().GetBalance(gomock.Any()).Return(uint256.NewInt(1000)),
db.EXPECT().SubBalance(gomock.Any(), gomock.Any(), tracing.BalanceDecreaseGasBuy),
db.EXPECT().RevertToSnapshot(15),
db.EXPECT().GetLogs(common.HexToHash(fmt.Sprintf("0x%016d%016d", 2, 1)), uint64(2), common.HexToHash(fmt.Sprintf("0x%016d", 2))),
db.EXPECT().GetLogs(common.HexToHash(fmt.Sprintf("0x%016d%016d", 2, 0)), uint64(2), common.HexToHash(fmt.Sprintf("0x%016d", 2))),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),

db.EXPECT().BeginBlock(uint64(2)),
db.EXPECT().BeginTransaction(uint32(2)),
db.EXPECT().SetTxContext(gomock.Any(), 2),
db.EXPECT().BeginBlock(uint64(3)),
db.EXPECT().BeginTransaction(uint32(0)),
db.EXPECT().SetTxContext(gomock.Any(), 1),
db.EXPECT().Snapshot().Return(15),
db.EXPECT().GetNonce(data.GetMessage().From).Return(uint64(1)),
db.EXPECT().GetCodeHash(data.GetMessage().From).Return(common.HexToHash("0x0")),
db.EXPECT().GetBalance(gomock.Any()).Return(uint256.NewInt(1000)),
db.EXPECT().SubBalance(gomock.Any(), gomock.Any(), tracing.BalanceDecreaseGasBuy),
db.EXPECT().RevertToSnapshot(15),
db.EXPECT().GetLogs(common.HexToHash(fmt.Sprintf("0x%016d%016d", 2, 2)), uint64(2), common.HexToHash(fmt.Sprintf("0x%016d", 2))),
db.EXPECT().GetLogs(common.HexToHash(fmt.Sprintf("0x%016d%016d", 3, 1)), uint64(3), common.HexToHash(fmt.Sprintf("0x%016d", 3))),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),
)
Expand Down Expand Up @@ -105,17 +105,18 @@ func TestVmSdb_Eth_AllTransactionsAreProcessedInOrder(t *testing.T) {
cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, false, "Cancun")
data := ethtest.CreateTestTransaction(t)

// Simulate the execution of three transactions in two blocks.
// Simulate the execution of 4 transactions
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
// Block 2
// Tx 1
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 2, Transaction: 1, Data: data})
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 2, Transaction: 2, Data: data})
// Block 3
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 3, Transaction: 1, Data: data})
//// Block 4
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 4, Transaction: utils.PseudoTx, Data: data})
// Tx 2
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 3, Transaction: 2, Data: data})
// Tx 3
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 4, Transaction: 3, Data: data})
// Tx 4
consumer(executor.TransactionInfo[txcontext.TxContext]{Block: 5, Transaction: utils.PseudoTx, Data: data})
return nil
})

Expand All @@ -126,39 +127,44 @@ func TestVmSdb_Eth_AllTransactionsAreProcessedInOrder(t *testing.T) {
gomock.InOrder(
ext.EXPECT().PreRun(executor.AtBlock[txcontext.TxContext](2), gomock.Any()),

// Block 2
// Tx 1
db.EXPECT().BeginBlock(uint64(2)),
db.EXPECT().BeginTransaction(uint32(1)),
db.EXPECT().BeginTransaction(uint32(0)),
ext.EXPECT().PreBlock(executor.AtTransaction[txcontext.TxContext](2, 0), gomock.Any()),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](2, 1), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](2, 1), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](2, 1), gomock.Any()),
ext.EXPECT().PostBlock(executor.AtTransaction[txcontext.TxContext](2, 1), gomock.Any()),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),
// Tx 2
db.EXPECT().BeginBlock(uint64(2)),
db.EXPECT().BeginTransaction(uint32(2)),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](2, 2), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](2, 2), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](2, 2), gomock.Any()),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),
//
//// Block 3
db.EXPECT().BeginBlock(uint64(3)),
db.EXPECT().BeginTransaction(uint32(1)),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](3, 1), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](3, 1), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](3, 1), gomock.Any()),
ext.EXPECT().PreBlock(executor.AtTransaction[txcontext.TxContext](3, 1), gomock.Any()),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](3, 2), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](3, 2), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](3, 2), gomock.Any()),
ext.EXPECT().PostBlock(executor.AtTransaction[txcontext.TxContext](3, 2), gomock.Any()),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),
//
//// Block 4
// Tx 3
db.EXPECT().BeginBlock(uint64(4)),
db.EXPECT().BeginTransaction(uint32(utils.PseudoTx)),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](4, utils.PseudoTx), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](4, utils.PseudoTx), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](4, utils.PseudoTx), gomock.Any()),
db.EXPECT().BeginTransaction(uint32(2)),
ext.EXPECT().PreBlock(executor.AtTransaction[txcontext.TxContext](4, 2), gomock.Any()),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](4, 3), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](4, 3), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](4, 3), gomock.Any()),
ext.EXPECT().PostBlock(executor.AtTransaction[txcontext.TxContext](4, 3), gomock.Any()),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),
// Tx 4
db.EXPECT().BeginBlock(uint64(5)),
db.EXPECT().BeginTransaction(uint32(3)),
ext.EXPECT().PreBlock(executor.AtTransaction[txcontext.TxContext](5, 3), gomock.Any()),
ext.EXPECT().PreTransaction(executor.AtTransaction[txcontext.TxContext](5, utils.PseudoTx), gomock.Any()),
processor.EXPECT().Process(executor.AtTransaction[txcontext.TxContext](5, utils.PseudoTx), gomock.Any()),
ext.EXPECT().PostTransaction(executor.AtTransaction[txcontext.TxContext](5, utils.PseudoTx), gomock.Any()),
ext.EXPECT().PostBlock(executor.AtTransaction[txcontext.TxContext](5, utils.PseudoTx), gomock.Any()),
db.EXPECT().EndTransaction(),
db.EXPECT().EndBlock(),
ext.EXPECT().PostRun(executor.AtBlock[txcontext.TxContext](5), gomock.Any(), nil),
Expand Down Expand Up @@ -200,7 +206,7 @@ func TestVmSdb_Eth_ValidationDoesNotFailOnValidTransaction(t *testing.T) {
gomock.InOrder(
// Tx execution
db.EXPECT().BeginBlock(uint64(2)),
db.EXPECT().BeginTransaction(uint32(1)),
db.EXPECT().BeginTransaction(uint32(0)),
db.EXPECT().SetTxContext(gomock.Any(), 1),
db.EXPECT().Snapshot().Return(15),
db.EXPECT().GetNonce(data.GetMessage().From).Return(uint64(1)),
Expand Down Expand Up @@ -262,7 +268,7 @@ func TestVmSdb_Eth_ValidationDoesFailOnInvalidTransaction(t *testing.T) {
db.EXPECT().GetCode(common.HexToAddress("0x2")).Return([]byte{}),
)
db.EXPECT().BeginBlock(uint64(2))
db.EXPECT().BeginTransaction(uint32(1))
db.EXPECT().BeginTransaction(uint32(0))

processor, err := executor.MakeEthTestProcessor(cfg)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions ethtest/block_enviroment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

type stBlockEnvironment struct {
blockNumber uint64
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
Random *BigInt `json:"currentRandom" gencodec:"optional"`
Difficulty *BigInt `json:"currentDifficulty" gencodec:"optional"`
Expand Down Expand Up @@ -74,7 +73,7 @@ func (s *stBlockEnvironment) GetGasLimit() uint64 {
}

func (s *stBlockEnvironment) GetNumber() uint64 {
return s.blockNumber
return s.Number.Uint64()
}

func (s *stBlockEnvironment) GetTimestamp() uint64 {
Expand Down
19 changes: 15 additions & 4 deletions ethtest/block_enviroment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func TestStBlockEnvironment_GetBaseFee(t *testing.T) {
}

func TestStBlockEnvironment_GetBlockHash_Correctly_Converts(t *testing.T) {
blockNum := uint64(10)
want := common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(blockNum)).String())))
env := &stBlockEnvironment{blockNumber: blockNum}
blockNum := int64(10)
want := common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(blockNum).String())))
env := &stBlockEnvironment{Number: newBigInt(blockNum)}

got, err := env.GetBlockHash(blockNum)
got, err := env.GetBlockHash(uint64(blockNum))
if err != nil {
t.Fatalf("cannot get block hash: %v", err)
}
Expand Down Expand Up @@ -186,3 +186,14 @@ func TestStBlockEnvironment_GetBlobBaseFee(t *testing.T) {
})
}
}

func TestStBlockEnvironment_CorrectBlockNumberIsReturned(t *testing.T) {
blkNumber := uint64(1)
env := &stBlockEnvironment{
Number: newBigInt(int64(blkNumber)),
}

if got, want := env.GetNumber(), blkNumber; got != want {
t.Errorf("unexpected block number, got: %v, want: %v", got, want)
}
}
28 changes: 13 additions & 15 deletions ethtest/mock_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ func CreateTestTransaction(t *testing.T) txcontext.TxContext {
to := common.HexToAddress("0x10")
return &stateTestContext{
env: &stBlockEnvironment{
blockNumber: 1,
Coinbase: common.Address{},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
chainCfg: chainCfg,
Coinbase: common.Address{},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
chainCfg: chainCfg,
},
inputState: types.GenesisAlloc{
common.HexToAddress("0x1"): core.GenesisAccount{
Expand Down Expand Up @@ -83,13 +82,12 @@ func CreateTestStJson(*testing.T) *stJSON {
return &stJSON{
path: "test/path",
Env: stBlockEnvironment{
blockNumber: 1,
Coinbase: common.Address{0x1},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
Coinbase: common.Address{0x1},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
},
Pre: types.GenesisAlloc{common.Address{0x2}: types.Account{
Code: []byte{1},
Expand Down
2 changes: 1 addition & 1 deletion executor/eth_test_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (e ethTestProvider) Run(_ int, _ int, consumer Consumer[txcontext.TxContext
for i, tx := range tests {
err = consumer(TransactionInfo[txcontext.TxContext]{
// Blocks 0 and 1 are used by priming
Block: 2,
Block: 2 + i,
Transaction: i,
Data: tx.Ctx,
})
Expand Down
6 changes: 3 additions & 3 deletions executor/eth_test_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func Test_ethTestProvider_Run(t *testing.T) {

gomock.InOrder(
consumer.EXPECT().Consume(2, 0, gomock.Any()),
consumer.EXPECT().Consume(2, 1, gomock.Any()),
consumer.EXPECT().Consume(2, 2, gomock.Any()),
consumer.EXPECT().Consume(2, 3, gomock.Any()),
consumer.EXPECT().Consume(3, 1, gomock.Any()),
consumer.EXPECT().Consume(4, 2, gomock.Any()),
consumer.EXPECT().Consume(5, 3, gomock.Any()),
)

err := provider.Run(0, 0, toSubstateConsumer(consumer))
Expand Down
4 changes: 2 additions & 2 deletions executor/extension/logger/eth_state_test_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func makeEthStateTestLogger(log logger.Logger, frequency int) *ethStateTestLogge
}
}

// PreTransaction reports test name and fork.
func (l *ethStateTestLogger) PreTransaction(s executor.State[txcontext.TxContext], _ *executor.Context) error {
// PreBlock reports test name and fork.
func (l *ethStateTestLogger) PreBlock(s executor.State[txcontext.TxContext], _ *executor.Context) error {
l.log.Infof("Currently running:\n%s", s.Data)
l.overall++
if l.overall%l.reportFrequency == 0 {
Expand Down
6 changes: 3 additions & 3 deletions executor/extension/logger/eth_state_test_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.uber.org/mock/gomock"
)

func TestEthStateTestLogger_PreTransactionLogsProgress(t *testing.T) {
func TestEthStateTestLogger_PreBlockLogsProgress(t *testing.T) {
ctrl := gomock.NewController(t)
log := logger.NewMockLogger(ctrl)
ext := makeEthStateTestLogger(log, 2)
Expand All @@ -22,12 +22,12 @@ func TestEthStateTestLogger_PreTransactionLogsProgress(t *testing.T) {
log.EXPECT().Noticef("%v tests has been processed so far...", 2),
)

err := ext.PreTransaction(s, &executor.Context{})
err := ext.PreBlock(s, &executor.Context{})
if err != nil {
t.Fatalf("pre-tx failed: %v", err)
}

err = ext.PreTransaction(s, &executor.Context{})
err = ext.PreBlock(s, &executor.Context{})
if err != nil {
t.Fatalf("pre-tx failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion executor/extension/primer/eth_state_test_db_primer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ethStateTestDbPrimer struct {
log logger.Logger
}

func (e ethStateTestDbPrimer) PreTransaction(st executor.State[txcontext.TxContext], ctx *executor.Context) error {
func (e ethStateTestDbPrimer) PreBlock(st executor.State[txcontext.TxContext], ctx *executor.Context) error {
primeCtx := utils.NewPrimeContext(e.cfg, ctx.State, 0, e.log)
return primeCtx.PrimeStateDB(st.Data.GetInputState(), ctx.State)
}
8 changes: 4 additions & 4 deletions executor/extension/primer/eth_state_test_db_primer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"go.uber.org/mock/gomock"
)

func Test_EthStateTestDbPrimer_PreTransactionPriming(t *testing.T) {
func Test_EthStateTestDbPrimer_PreBlockPriming(t *testing.T) {
cfg := &utils.Config{}
ext := ethStateTestDbPrimer{cfg: cfg, log: logger.NewLogger(cfg.LogLevel, "EthStatePrimer")}

Expand Down Expand Up @@ -57,13 +57,13 @@ func Test_EthStateTestDbPrimer_PreTransactionPriming(t *testing.T) {

ctx.State = mockState

err := ext.PreTransaction(st, ctx)
err := ext.PreBlock(st, ctx)
if err != nil {
t.Fatalf("unexpected err; %v", err)
}
}

func Test_EthStateTestDbPrimer_PreTransactionPrimingWorksWithPreExistedStateDb(t *testing.T) {
func Test_EthStateTestDbPrimer_PreBlockPrimingWorksWithPreExistedStateDb(t *testing.T) {
cfg := &utils.Config{}
ext := ethStateTestDbPrimer{cfg: cfg, log: logger.NewLogger(cfg.LogLevel, "EthStatePrimer")}

Expand Down Expand Up @@ -92,7 +92,7 @@ func Test_EthStateTestDbPrimer_PreTransactionPrimingWorksWithPreExistedStateDb(t

ctx.State = mockState

err := ext.PreTransaction(st, ctx)
err := ext.PreBlock(st, ctx)
if err != nil {
t.Fatalf("unexpected err; %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions executor/extension/statedb/eth_state_test_db_prepper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ethStateTestDbPrepper struct {
log logger.Logger
}

func (e ethStateTestDbPrepper) PreTransaction(_ executor.State[txcontext.TxContext], ctx *executor.Context) error {
func (e ethStateTestDbPrepper) PreBlock(_ executor.State[txcontext.TxContext], ctx *executor.Context) error {
var err error
cfg := e.cfg
// We reduce the node cache size to be used by Carmen to 1 MB
Expand All @@ -63,7 +63,7 @@ func (e ethStateTestDbPrepper) PreTransaction(_ executor.State[txcontext.TxConte
return nil
}

func (e ethStateTestDbPrepper) PostTransaction(_ executor.State[txcontext.TxContext], ctx *executor.Context) error {
func (e ethStateTestDbPrepper) PostBlock(_ executor.State[txcontext.TxContext], ctx *executor.Context) error {
if ctx.State != nil {
err := ctx.State.Close()
if err != nil {
Expand Down
Loading

0 comments on commit 8464f54

Please sign in to comment.