diff --git a/builder/builder.go b/builder/builder.go index 5091cf441f..565a8d2d6a 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -354,8 +354,7 @@ func (b *Builder) runTxn(txn *mempool.BroadcastedTransaction) error { feeUnit = core.STRK } if trace[0].StateDiff.DeclaredClasses != nil { - switch t := (txn.Transaction).(type) { - case *core.DeclareTransaction: + if t, ok := (txn.Transaction).(*core.DeclareTransaction); ok { err := state.SetContractClass(t.ClassHash, txn.DeclaredClass) if err != nil { b.log.Errorw("failed to set contract class : %s", err) diff --git a/builder/builder_test.go b/builder/builder_test.go index 984b504d61..21a74e71c4 100644 --- a/builder/builder_test.go +++ b/builder/builder_test.go @@ -442,7 +442,7 @@ func TestPrefundedAccounts(t *testing.T) { genesisConfig, err := genesis.Read("../genesis/genesis_prefund_accounts.json") require.NoError(t, err) genesisConfig.Classes = []string{"../genesis/classes/strk.json", "../genesis/classes/account.json"} - diff, classes, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), bc.Network()) + diff, classes, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), bc.Network(), 40000000) //nolint:gomnd require.NoError(t, err) require.NoError(t, bc.StoreGenesis(diff, classes)) diff --git a/genesis/genesis.go b/genesis/genesis.go index 66d39dc166..2f4686adae 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -88,6 +88,7 @@ func GenesisStateDiff( config *GenesisConfig, v vm.VM, network *utils.Network, + maxSteps uint64, ) (*core.StateDiff, map[felt.Felt]core.Class, error) { newClasses, err := loadClasses(config.Classes) if err != nil { @@ -132,7 +133,6 @@ func GenesisStateDiff( Timestamp: 0, }, } - maxSteps := uint64(100000) //nolint:gomnd // Call the constructors if _, err = v.Call(callInfo, &blockInfo, genesisState, network, maxSteps, false); err != nil { return nil, nil, fmt.Errorf("execute function call: %v", err) @@ -158,7 +158,6 @@ func GenesisStateDiff( Timestamp: 0, }, } - maxSteps := uint64(100000) //nolint:gomnd if _, err = v.Call(callInfo, &blockInfo, genesisState, network, maxSteps, false); err != nil { return nil, nil, fmt.Errorf("execute function call: %v", err) } diff --git a/genesis/genesis_test.go b/genesis/genesis_test.go index c63f2ac72f..85f60087ac 100644 --- a/genesis/genesis_test.go +++ b/genesis/genesis_test.go @@ -34,7 +34,7 @@ func TestGenesisStateDiff(t *testing.T) { t.Run("empty genesis config", func(t *testing.T) { genesisConfig := genesis.GenesisConfig{} - _, _, err := genesis.GenesisStateDiff(&genesisConfig, vm.New(false, log), network) + _, _, err := genesis.GenesisStateDiff(&genesisConfig, vm.New(false, log), network, 40000000) //nolint:gomnd require.NoError(t, err) }) @@ -42,7 +42,7 @@ func TestGenesisStateDiff(t *testing.T) { genesisConfig, err := genesis.Read("./genesis_prefund_accounts.json") require.NoError(t, err) genesisConfig.Classes = []string{"./classes/strk.json", "./classes/account.json"} - stateDiff, newClasses, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), network) + stateDiff, newClasses, err := genesis.GenesisStateDiff(genesisConfig, vm.New(false, log), network, 40000000) //nolint:gomnd require.NoError(t, err) require.Empty(t, stateDiff.Nonces) require.Equal(t, 2, len(stateDiff.DeclaredV1Classes)) diff --git a/node/genesis.go b/node/genesis.go index 135e559b36..2e9a7b87b8 100644 --- a/node/genesis.go +++ b/node/genesis.go @@ -11,7 +11,7 @@ import ( "github.com/NethermindEth/juno/vm" ) -func buildGenesis(genesisPath string, sequencerMode bool, bc *blockchain.Blockchain, v vm.VM) error { +func buildGenesis(genesisPath string, sequencerMode bool, bc *blockchain.Blockchain, v vm.VM, maxSteps uint64) error { if _, err := bc.Height(); !errors.Is(err, db.ErrKeyNotFound) { return err } @@ -25,7 +25,7 @@ func buildGenesis(genesisPath string, sequencerMode bool, bc *blockchain.Blockch return err } - diff, classes, err = genesis.GenesisStateDiff(genesisConfig, v, bc.Network()) + diff, classes, err = genesis.GenesisStateDiff(genesisConfig, v, bc.Network(), maxSteps) if err != nil { return err } diff --git a/node/node.go b/node/node.go index 7003efff4a..d50669c0f2 100644 --- a/node/node.go +++ b/node/node.go @@ -171,8 +171,8 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen } poolDB, _ := pebble.NewMem() p := mempool.New(poolDB) - sequencer := builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, time.Second*time.Duration(cfg.SeqBlockTime), p, //nolint: gomnd,lll - log) + sequencer := builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, //nolint:mnd + time.Second*time.Duration(cfg.SeqBlockTime), p, log) rpcHandler = rpc.New(chain, sequencer, throttledVM, version, log).WithMempool(p).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps)) services = append(services, sequencer) } else { @@ -374,7 +374,7 @@ func (n *Node) Run(ctx context.Context) { n.log.Errorw("Error while migrating the DB", "err", err) return } - if err = buildGenesis(n.cfg.GenesisFile, n.cfg.Sequencer, n.blockchain, vm.New(false, n.log)); err != nil { + if err = buildGenesis(n.cfg.GenesisFile, n.cfg.Sequencer, n.blockchain, vm.New(false, n.log), uint64(n.cfg.RPCCallMaxSteps)); err != nil { n.log.Errorw("Error building genesis state", "err", err) return }