From 44e87966e445bfe8d2b522fd45dc562eb0d92209 Mon Sep 17 00:00:00 2001 From: rian Date: Tue, 17 Dec 2024 15:44:54 +0200 Subject: [PATCH] revert unneeded changes --- .gitignore | 10 +---- Makefile | 4 +- blockchain/blockchain.go | 45 +++---------------- blockchain/blockchain_test.go | 2 +- cmd/juno/juno.go | 8 ++-- core/block.go | 1 + core/felt/felt.go | 4 +- core/state.go | 30 ++++++++----- core/state_test.go | 83 +++++++++++++++++++++-------------- core/state_update.go | 2 + core/transaction.go | 10 ++--- grpc/gen/kv.pb.go | 13 +++--- node/node.go | 2 +- sync/pending.go | 1 - vm/trace.go | 2 +- vm/vm.go | 2 +- vm/vm_test.go | 20 ++++----- 17 files changed, 113 insertions(+), 126 deletions(-) diff --git a/.gitignore b/.gitignore index 9534063762..1fe2bcf077 100644 --- a/.gitignore +++ b/.gitignore @@ -6,14 +6,8 @@ build/ coverage/* config/ .envrc -seq-db/ - -# pyenv .python-version - # Default path for Juno DB files. It will get created if you follow the # README and/or run `./build/juno` command. -juno/ -p2p-dbs - -myplugin.so +/juno/ +p2p-dbs \ No newline at end of file diff --git a/Makefile b/Makefile index 433aeeafbf..694bff7768 100644 --- a/Makefile +++ b/Makefile @@ -203,7 +203,7 @@ sequencer-with-accounts: --rpc-call-max-steps=4123000 -sequencer-shadow-sepolia: +sequencer-shadow-sepolia: # Only works for 0.12.3 Sepolia blocks ./build/juno \ --http \ --http-port=6066 \ @@ -213,7 +213,7 @@ sequencer-shadow-sepolia: --seq-enable \ --seq-shadow-mode \ --seq-block-time=5 \ - --seq-shadow-mode-sync-to=0 \ + --seq-shadow-mode-sync-to-block=0 \ --seq-rpc-endpoint="" \ --network sepolia \ --disable-l1-verification \ diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index d6a8852d56..2e04a18edf 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -320,18 +320,9 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit return err } - state := core.NewState(txn) - if err := state.Update(block.Number, stateUpdate.StateDiff, newClasses); err != nil { + if err := core.NewState(txn).Update(block.Number, stateUpdate, newClasses); err != nil { return err } - stateRoot, err := state.Root() - if err != nil { - return err - } - - if !stateRoot.Equal(stateUpdate.NewRoot) { - return fmt.Errorf("new state root does not match expected root") - } if err := StoreBlockHeader(txn, block.Header); err != nil { return err } @@ -503,7 +494,7 @@ func TransactionsByBlockNumber(txn db.Transaction, number uint64) ([]core.Transa return nil, err } - txs := []core.Transaction{} + var txs []core.Transaction numBytes := core.MarshalBlockNumber(number) prefix := db.TransactionsByBlockNumberAndIndex.Key(numBytes) @@ -538,7 +529,7 @@ func receiptsByBlockNumber(txn db.Transaction, number uint64) ([]*core.Transacti return nil, err } - receipts := []*core.TransactionReceipt{} + var receipts []*core.TransactionReceipt numBytes := core.MarshalBlockNumber(number) prefix := db.ReceiptsByBlockNumberAndIndex.Key(numBytes) @@ -871,10 +862,6 @@ func (b *Blockchain) revertHead(txn db.Transaction) error { return err } - if err = b.verifyStateUpdateRoot(state, stateUpdate.OldRoot); err != nil { - return err - } - header, err := blockHeaderByNumber(txn, blockNumber) if err != nil { return err @@ -943,26 +930,6 @@ func removeTxsAndReceipts(txn db.Transaction, blockNumber, numTxs uint64) error return nil } -func MakeStateDiffForEmptyBlock(bc Reader, blockNumber uint64) (*core.StateDiff, error) { - stateDiff := core.EmptyStateDiff() - - const blockHashLag = 10 - if blockNumber < blockHashLag { - return stateDiff, nil - } - - header, err := bc.BlockHeaderByNumber(blockNumber - blockHashLag) - if err != nil { - return nil, err - } - - blockHashStorageContract := new(felt.Felt).SetUint64(1) - stateDiff.StorageDiffs[*blockHashStorageContract] = map[felt.Felt]*felt.Felt{ - *new(felt.Felt).SetUint64(header.Number): header.Hash, - } - return stateDiff, nil -} - func (b *Blockchain) verifyStateUpdateRoot(s *core.State, root *felt.Felt) error { currentRoot, err := s.Root() if err != nil { @@ -970,7 +937,7 @@ func (b *Blockchain) verifyStateUpdateRoot(s *core.State, root *felt.Felt) error } if !root.Equal(currentRoot) { - return fmt.Errorf("state's current root: %s does not match the expected root: %s", currentRoot, root) + return fmt.Errorf("state's current state root: %s does not match the expected state root: %s", currentRoot, root) } return nil } @@ -996,7 +963,7 @@ func (b *Blockchain) Finalise( //nolint:gocyclo return err } stateUpdate.OldRoot = oldStateRoot - if err = state.Update(block.Number, stateUpdate.StateDiff, newClasses); err != nil { + if err = state.Update(block.Number, stateUpdate, newClasses); err != nil { return err } newStateRoot, err := state.Root() @@ -1032,7 +999,7 @@ func (b *Blockchain) Finalise( //nolint:gocyclo } if !newStateRoot.Equal(block.GlobalStateRoot) { - return fmt.Errorf("new pe root does not match expected root") + return fmt.Errorf("new state root does not match expected state root") } if err := StoreBlockHeader(txn, block.Header); err != nil { diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index 7c3d6f0152..114eb6e4d2 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -286,7 +286,7 @@ func TestStore(t *testing.T) { wrongRootStateUpdate.NewRoot = new(felt.Felt).SetUint64(1337) chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet, nil) require.ErrorContains(t, chain.Store(block0, &emptyCommitments, wrongRootStateUpdate, nil), - "new state root does not match expected root") + "does not match the expected root") }) } diff --git a/cmd/juno/juno.go b/cmd/juno/juno.go index 31ec361c89..a476a75e84 100644 --- a/cmd/juno/juno.go +++ b/cmd/juno/juno.go @@ -89,7 +89,7 @@ const ( seqBlockTimeF = "seq-block-time" seqGenesisFileF = "seq-genesis-file" seqShadowModeF = "seq-shadow-mode" - seqShadowModeSyncToF = "seq-shadow-mode-sync-to" + seqShadowModeSyncToF = "seq-shadow-mode-sync-to-block" seqDisableFeesF = "seq-disable-fees" defaultConfig = "" @@ -195,8 +195,8 @@ const ( seqBlockTimeUsage = "Time to build a block, in seconds" seqGenesisFileUsage = "Path to the genesis file" seqShadowModeUsage = "Launches the sequencer in shadow mode (note: network must be set to Sepolia)" - seqShadowModeSyncToUsage = "The Sepolia block that the Sequencer should sync to before Sequencing" - seqDisableFeesUsage = "Skip charge fee for sequencer execution (note: not for shadowing)" + seqShadowModeSyncToUsage = "The block number that the Sequencer should sync to before Sequencing" + seqDisableFeesUsage = "Skip charge fee for sequencer execution" ) var Version string @@ -385,13 +385,13 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr junoCmd.Flags().String(versionedConstantsFileF, defaultVersionedConstantsFile, versionedConstantsFileUsage) junoCmd.MarkFlagsMutuallyExclusive(p2pFeederNodeF, p2pPeersF) junoCmd.Flags().String(pluginPathF, defaultPluginPath, pluginPathUsage) + junoCmd.AddCommand(GenP2PKeyPair(), DBCmd(defaultDBPath)) junoCmd.Flags().Bool(seqEnF, defaultSeqEn, seqEnUsage) junoCmd.Flags().String(seqRPCEndpointF, defaultSeqRPCEndpoint, seqRPCEndpointUsage) junoCmd.Flags().Uint(seqBlockTimeF, defaultSeqBlockTime, seqBlockTimeUsage) junoCmd.Flags().String(seqGenesisFileF, defaultSeqGenesisFile, seqGenesisFileUsage) junoCmd.Flags().Bool(seqShadowModeF, defaultSeqShadowMode, seqShadowModeUsage) junoCmd.Flags().Uint(seqShadowModeSyncToF, defaultSeqShadowModeSyncTo, seqShadowModeSyncToUsage) - junoCmd.AddCommand(GenP2PKeyPair(), DBCmd(defaultDBPath)) junoCmd.Flags().Bool(seqDisableFeesF, defaultSeqDisableFees, seqDisableFeesUsage) return junoCmd } diff --git a/core/block.go b/core/block.go index db967d6aec..6af709232c 100644 --- a/core/block.go +++ b/core/block.go @@ -90,6 +90,7 @@ func VerifyBlockHash(b *Block, network *utils.Network, stateDiff *StateDiff) (*B metaInfo := network.BlockHashMetaInfo unverifiableRange := metaInfo.UnverifiableRange + skipVerification := unverifiableRange != nil && b.Number >= unverifiableRange[0] && b.Number <= unverifiableRange[1] //nolint:gocritic // todo should we still keep it after p2p ? if !skipVerification { diff --git a/core/felt/felt.go b/core/felt/felt.go index 7e546c621c..284e7a064b 100644 --- a/core/felt/felt.go +++ b/core/felt/felt.go @@ -45,10 +45,10 @@ func (z *Felt) Impl() *fp.Element { return &z.val } -// UnmarshalText accepts numbers and strings as input. +// UnmarshalJSON accepts numbers and strings as input. // See Element.SetString for valid prefixes (0x, 0b, ...). // If there is an error, we try to explicitly unmarshal from hex before -// returning an error. This implementation is based on [gnark-crypto]'s UnmarshalText. +// returning an error. This implementation is based on [gnark-crypto]'s UnmarshalJSON. // // [gnark-crypto]: https://github.com/ConsenSys/gnark-crypto/blob/master/ecc/stark-curve/fp/element.go func (z *Felt) UnmarshalJSON(data []byte) error { diff --git a/core/state.go b/core/state.go index db1a655a86..8283219a87 100644 --- a/core/state.go +++ b/core/state.go @@ -120,6 +120,7 @@ func (s *State) Root() (*felt.Felt, error) { if classesRoot.IsZero() { return storageRoot, nil } + return crypto.PoseidonArray(stateVersion, storageRoot, classesRoot), nil } @@ -187,23 +188,29 @@ func (s *State) verifyStateUpdateRoot(root *felt.Felt) error { return err } - if !root.Equal(currentRoot) { + if root != nil && !root.Equal(currentRoot) { return fmt.Errorf("state's current root: %s does not match the expected root: %s", currentRoot, root) } return nil } // Update applies a StateUpdate to the State object. State is not -// updated if an error is encountered during the operation. -func (s *State) Update(blockNumber uint64, diff *StateDiff, declaredClasses map[felt.Felt]Class) error { +// updated if an error is encountered during the operation. If update's +// old or new root does not match the state's old or new roots, +// [ErrMismatchedRoot] is returned. +func (s *State) Update(blockNumber uint64, update *StateUpdate, declaredClasses map[felt.Felt]Class) error { + fmt.Println("--=") + err := s.verifyStateUpdateRoot(update.OldRoot) + if err != nil { + return err + } // register declared classes mentioned in stateDiff.deployedContracts and stateDiff.declaredClasses for cHash, class := range declaredClasses { - if err := s.putClass(&cHash, class, blockNumber); err != nil { + if err = s.putClass(&cHash, class, blockNumber); err != nil { return err } } - - if err := s.updateDeclaredClassesTrie(diff.DeclaredV1Classes, declaredClasses); err != nil { + if err = s.updateDeclaredClassesTrie(update.StateDiff.DeclaredV1Classes, declaredClasses); err != nil { return err } @@ -213,17 +220,18 @@ func (s *State) Update(blockNumber uint64, diff *StateDiff, declaredClasses map[ } // register deployed contracts - for addr, classHash := range diff.DeployedContracts { + for addr, classHash := range update.StateDiff.DeployedContracts { if err = s.putNewContract(stateTrie, &addr, classHash, blockNumber); err != nil { return err } } - - if err = s.updateContracts(stateTrie, blockNumber, diff, true); err != nil { + if err = s.updateContracts(stateTrie, blockNumber, update.StateDiff, true); err != nil { return err } - - return storageCloser() + if err = storageCloser(); err != nil { + return err + } + return s.verifyStateUpdateRoot(update.NewRoot) } var ( diff --git a/core/state_test.go b/core/state_test.go index 1524bbf6f3..6b96d64b3b 100644 --- a/core/state_test.go +++ b/core/state_test.go @@ -3,6 +3,7 @@ package core_test import ( "context" "encoding/json" + "fmt" "os" "reflect" "testing" @@ -69,19 +70,39 @@ func TestUpdate(t *testing.T) { require.NoError(t, err) t.Run("empty state updated with mainnet block 0 state update", func(t *testing.T) { - require.NoError(t, state.Update(0, su0.StateDiff, nil)) + require.NoError(t, state.Update(0, su0, nil)) gotNewRoot, rerr := state.Root() require.NoError(t, rerr) assert.Equal(t, su0.NewRoot, gotNewRoot) }) + t.Run("error when state current root doesn't match state update's old root", func(t *testing.T) { + oldRoot := new(felt.Felt).SetBytes([]byte("some old root")) + su := &core.StateUpdate{ + OldRoot: oldRoot, + } + expectedErr := fmt.Sprintf("state's current root: %s does not match the expected root: %s", su0.NewRoot, oldRoot) + require.EqualError(t, state.Update(1, su, nil), expectedErr) + }) + + t.Run("error when state new root doesn't match state update's new root", func(t *testing.T) { + newRoot := new(felt.Felt).SetBytes([]byte("some new root")) + su := &core.StateUpdate{ + NewRoot: newRoot, + OldRoot: su0.NewRoot, + StateDiff: new(core.StateDiff), + } + expectedErr := fmt.Sprintf("state's current root: %s does not match the expected root: %s", su0.NewRoot, newRoot) + require.EqualError(t, state.Update(1, su, nil), expectedErr) + }) + t.Run("non-empty state updated multiple times", func(t *testing.T) { - require.NoError(t, state.Update(1, su1.StateDiff, nil)) + require.NoError(t, state.Update(1, su1, nil)) gotNewRoot, rerr := state.Root() require.NoError(t, rerr) assert.Equal(t, su1.NewRoot, gotNewRoot) - require.NoError(t, state.Update(2, su2.StateDiff, nil)) + require.NoError(t, state.Update(2, su2, nil)) gotNewRoot, err = state.Root() require.NoError(t, err) assert.Equal(t, su2.NewRoot, gotNewRoot) @@ -99,18 +120,12 @@ func TestUpdate(t *testing.T) { t.Run("post v0.11.0 declared classes affect root", func(t *testing.T) { t.Run("without class definition", func(t *testing.T) { - require.NoError(t, state.Update(3, su3.StateDiff, nil)) - root, err := state.Root() - require.NoError(t, err) - assert.NotEqual(t, root, su3.NewRoot) + require.Error(t, state.Update(3, su3, nil)) }) - require.NoError(t, state.Update(3, su3.StateDiff, map[felt.Felt]core.Class{ + require.NoError(t, state.Update(3, su3, map[felt.Felt]core.Class{ *utils.HexToFelt(t, "0xDEADBEEF"): &core.Cairo1Class{}, })) assert.NotEqual(t, su3.NewRoot, su3.OldRoot) - root, err := state.Root() - require.NoError(t, err) - assert.Equal(t, root, su3.NewRoot) }) // These value were taken from part of integration state update number 299762 @@ -128,7 +143,7 @@ func TestUpdate(t *testing.T) { } t.Run("update noClassContracts storage", func(t *testing.T) { - require.NoError(t, state.Update(4, su4.StateDiff, nil)) + require.NoError(t, state.Update(4, su4, nil)) gotValue, err := state.ContractStorage(scAddr, scKey) require.NoError(t, err) @@ -155,7 +170,7 @@ func TestUpdate(t *testing.T) { StorageDiffs: map[felt.Felt]map[felt.Felt]*felt.Felt{*scAddr2: {*scKey: scValue}}, }, } - assert.ErrorIs(t, state.Update(5, su5.StateDiff, nil), core.ErrContractNotDeployed) + assert.ErrorIs(t, state.Update(5, su5, nil), core.ErrContractNotDeployed) }) } @@ -178,8 +193,8 @@ func TestContractClassHash(t *testing.T) { su1, err := gw.StateUpdate(context.Background(), 1) require.NoError(t, err) - require.NoError(t, state.Update(0, su0.StateDiff, nil)) - require.NoError(t, state.Update(1, su1.StateDiff, nil)) + require.NoError(t, state.Update(0, su0, nil)) + require.NoError(t, state.Update(1, su1, nil)) allDeployedContracts := make(map[felt.Felt]*felt.Felt) @@ -210,7 +225,7 @@ func TestContractClassHash(t *testing.T) { }, } - require.NoError(t, state.Update(2, replaceUpdate.StateDiff, nil)) + require.NoError(t, state.Update(2, replaceUpdate, nil)) gotClassHash, err := state.ContractClassHash(new(felt.Felt).Set(&su1FirstDeployedAddress)) require.NoError(t, err) @@ -242,7 +257,7 @@ func TestNonce(t *testing.T) { }, } - require.NoError(t, state.Update(0, su.StateDiff, nil)) + require.NoError(t, state.Update(0, su, nil)) t.Run("newly deployed contract has zero nonce", func(t *testing.T) { nonce, err := state.ContractNonce(addr) @@ -260,7 +275,7 @@ func TestNonce(t *testing.T) { }, } - require.NoError(t, state.Update(1, su.StateDiff, nil)) + require.NoError(t, state.Update(1, su, nil)) gotNonce, err := state.ContractNonce(addr) require.NoError(t, err) @@ -282,7 +297,7 @@ func TestStateHistory(t *testing.T) { state := core.NewState(txn) su0, err := gw.StateUpdate(context.Background(), 0) require.NoError(t, err) - require.NoError(t, state.Update(0, su0.StateDiff, nil)) + require.NoError(t, state.Update(0, su0, nil)) contractAddr := utils.HexToFelt(t, "0x20cfa74ee3564b4cd5435cdace0f9c4d43b939620e4a0bb5076105df0a626c6") changedLoc := utils.HexToFelt(t, "0x5") @@ -308,7 +323,7 @@ func TestStateHistory(t *testing.T) { }, }, } - require.NoError(t, state.Update(1, su.StateDiff, nil)) + require.NoError(t, state.Update(1, su, nil)) t.Run("should give old value for a location that changed after the given height", func(t *testing.T) { oldValue, err := state.ContractStorageAt(contractAddr, changedLoc, 0) @@ -336,8 +351,8 @@ func TestContractIsDeployedAt(t *testing.T) { su1, err := gw.StateUpdate(context.Background(), 1) require.NoError(t, err) - require.NoError(t, state.Update(0, su0.StateDiff, nil)) - require.NoError(t, state.Update(1, su1.StateDiff, nil)) + require.NoError(t, state.Update(0, su0, nil)) + require.NoError(t, state.Update(1, su1, nil)) t.Run("deployed on genesis", func(t *testing.T) { deployedOn0 := utils.HexToFelt(t, "0x20cfa74ee3564b4cd5435cdace0f9c4d43b939620e4a0bb5076105df0a626c6") @@ -390,7 +405,7 @@ func TestClass(t *testing.T) { state := core.NewState(txn) su0, err := gw.StateUpdate(context.Background(), 0) require.NoError(t, err) - require.NoError(t, state.Update(0, su0.StateDiff, map[felt.Felt]core.Class{ + require.NoError(t, state.Update(0, su0, map[felt.Felt]core.Class{ *cairo0Hash: cairo0Class, *cairo1Hash: cairo1Class, })) @@ -419,10 +434,10 @@ func TestRevert(t *testing.T) { state := core.NewState(txn) su0, err := gw.StateUpdate(context.Background(), 0) require.NoError(t, err) - require.NoError(t, state.Update(0, su0.StateDiff, nil)) + require.NoError(t, state.Update(0, su0, nil)) su1, err := gw.StateUpdate(context.Background(), 1) require.NoError(t, err) - require.NoError(t, state.Update(1, su1.StateDiff, nil)) + require.NoError(t, state.Update(1, su1, nil)) t.Run("revert a replaced class", func(t *testing.T) { replaceStateUpdate := &core.StateUpdate{ @@ -435,7 +450,7 @@ func TestRevert(t *testing.T) { }, } - require.NoError(t, state.Update(2, replaceStateUpdate.StateDiff, nil)) + require.NoError(t, state.Update(2, replaceStateUpdate, nil)) require.NoError(t, state.Revert(2, replaceStateUpdate)) classHash, sErr := state.ContractClassHash(new(felt.Felt).Set(&su1FirstDeployedAddress)) require.NoError(t, sErr) @@ -453,7 +468,7 @@ func TestRevert(t *testing.T) { }, } - require.NoError(t, state.Update(2, nonceStateUpdate.StateDiff, nil)) + require.NoError(t, state.Update(2, nonceStateUpdate, nil)) require.NoError(t, state.Revert(2, nonceStateUpdate)) nonce, sErr := state.ContractNonce(new(felt.Felt).Set(&su1FirstDeployedAddress)) require.NoError(t, sErr) @@ -505,7 +520,7 @@ func TestRevert(t *testing.T) { }, } - require.NoError(t, state.Update(2, declaredClassesStateUpdate.StateDiff, classesM)) + require.NoError(t, state.Update(2, declaredClassesStateUpdate, classesM)) require.NoError(t, state.Revert(2, declaredClassesStateUpdate)) var decClass *core.DeclaredClass @@ -521,7 +536,7 @@ func TestRevert(t *testing.T) { su2, err := gw.StateUpdate(context.Background(), 2) require.NoError(t, err) t.Run("should be able to apply new update after a Revert", func(t *testing.T) { - require.NoError(t, state.Update(2, su2.StateDiff, nil)) + require.NoError(t, state.Update(2, su2, nil)) }) t.Run("should be able to revert all the state", func(t *testing.T) { @@ -576,7 +591,7 @@ func TestRevertGenesisStateDiff(t *testing.T) { }, }, } - require.NoError(t, state.Update(0, su.StateDiff, nil)) + require.NoError(t, state.Update(0, su, nil)) require.NoError(t, state.Revert(0, su)) } @@ -596,7 +611,7 @@ func TestRevertNoClassContracts(t *testing.T) { su0, err := gw.StateUpdate(context.Background(), 0) require.NoError(t, err) - require.NoError(t, state.Update(0, su0.StateDiff, nil)) + require.NoError(t, state.Update(0, su0, nil)) su1, err := gw.StateUpdate(context.Background(), 1) require.NoError(t, err) @@ -612,7 +627,7 @@ func TestRevertNoClassContracts(t *testing.T) { su1.StateDiff.StorageDiffs[*scAddr] = map[felt.Felt]*felt.Felt{*scKey: scValue} - require.NoError(t, state.Update(1, su1.StateDiff, nil)) + require.NoError(t, state.Update(1, su1, nil)) require.NoError(t, state.Revert(1, su1)) @@ -649,7 +664,7 @@ func TestRevertDeclaredClasses(t *testing.T) { *sierraHash: &core.Cairo1Class{}, } - require.NoError(t, state.Update(0, declareDiff.StateDiff, newClasses)) + require.NoError(t, state.Update(0, declareDiff, newClasses)) declaredClass, err := state.Class(classHash) require.NoError(t, err) assert.Equal(t, uint64(0), declaredClass.At) @@ -658,7 +673,7 @@ func TestRevertDeclaredClasses(t *testing.T) { assert.Equal(t, uint64(0), sierraClass.At) declareDiff.OldRoot = declareDiff.NewRoot - require.NoError(t, state.Update(1, declareDiff.StateDiff, newClasses)) + require.NoError(t, state.Update(1, declareDiff, newClasses)) t.Run("re-declaring a class shouldnt change it's DeclaredAt attribute", func(t *testing.T) { declaredClass, err = state.Class(classHash) diff --git a/core/state_update.go b/core/state_update.go index ef86d382cd..d51a159f58 100644 --- a/core/state_update.go +++ b/core/state_update.go @@ -204,6 +204,7 @@ func EmptyStateDiff() *StateDiff { func (d *StateDiff) Length() uint64 { var length int + for _, storageDiff := range d.StorageDiffs { length += len(storageDiff) } @@ -212,6 +213,7 @@ func (d *StateDiff) Length() uint64 { length += len(d.DeclaredV0Classes) length += len(d.DeclaredV1Classes) length += len(d.ReplacedClasses) + return uint64(length) } diff --git a/core/transaction.go b/core/transaction.go index 19d52a9b77..7dfe9d76e4 100644 --- a/core/transaction.go +++ b/core/transaction.go @@ -100,6 +100,11 @@ type ExecutionResources struct { TotalGasConsumed *GasConsumed } +type DataAvailability struct { + L1Gas uint64 + L1DataGas uint64 +} + type BuiltinInstanceCounter struct { Pedersen uint64 RangeCheck uint64 @@ -115,11 +120,6 @@ type BuiltinInstanceCounter struct { RangeCheck96 uint64 } -type DataAvailability struct { - L1Gas uint64 - L1DataGas uint64 -} - type Transaction interface { Hash() *felt.Felt Signature() []*felt.Felt diff --git a/grpc/gen/kv.pb.go b/grpc/gen/kv.pb.go index 8bc7691f68..aa28a6f28a 100644 --- a/grpc/gen/kv.pb.go +++ b/grpc/gen/kv.pb.go @@ -7,9 +7,10 @@ package gen import ( - empty "github.com/golang/protobuf/ptypes/empty" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" reflect "reflect" sync "sync" ) @@ -365,11 +366,11 @@ func file_kv_proto_rawDescGZIP() []byte { var file_kv_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_kv_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_kv_proto_goTypes = []interface{}{ - (Op)(0), // 0: database.Op - (*Cursor)(nil), // 1: database.Cursor - (*Pair)(nil), // 2: database.Pair - (*VersionReply)(nil), // 3: database.VersionReply - (*empty.Empty)(nil), // 4: google.protobuf.Empty + (Op)(0), // 0: database.Op + (*Cursor)(nil), // 1: database.Cursor + (*Pair)(nil), // 2: database.Pair + (*VersionReply)(nil), // 3: database.VersionReply + (*emptypb.Empty)(nil), // 4: google.protobuf.Empty } var file_kv_proto_depIdxs = []int32{ 0, // 0: database.Cursor.op:type_name -> database.Op diff --git a/node/node.go b/node/node.go index 06e31a3426..10839260e2 100644 --- a/node/node.go +++ b/node/node.go @@ -102,7 +102,7 @@ type Config struct { SeqBlockTime uint `mapstructure:"seq-block-time"` SeqGenesisFile string `mapstructure:"seq-genesis-file"` SeqShadowMode bool `mapstructure:"seq-shadow-mode"` - SeqShadowModeSyncTo uint64 `mapstructure:"seq-shadow-mode-sync-to"` + SeqShadowModeSyncTo uint64 `mapstructure:"seq-shadow-mode-sync-to-block"` SeqDisableFees bool `mapstructure:"seq-disable-fees"` } diff --git a/sync/pending.go b/sync/pending.go index 29079e5adc..c9f2430637 100644 --- a/sync/pending.go +++ b/sync/pending.go @@ -93,7 +93,6 @@ func (p *PendingStateWriter) SetStorage(contractAddress, key, value *felt.Felt) } func (p *PendingStateWriter) IncrementNonce(contractAddress *felt.Felt) error { - fmt.Println(" -> IncrementNonce", contractAddress.String()) currentNonce, err := p.ContractNonce(contractAddress) if err != nil { return fmt.Errorf("get contract nonce: %v", err) diff --git a/vm/trace.go b/vm/trace.go index 1219fa4781..83bf029970 100644 --- a/vm/trace.go +++ b/vm/trace.go @@ -190,7 +190,7 @@ func (t *TransactionTrace) AllEvents() []OrderedEvent { addEvents(t.ConstructorInvocation) } addEvents(t.FeeTransferInvocation) - addEvents(t.FunctionInvocation) // Todo: Is this is in the right place? + addEvents(t.FunctionInvocation) return events } diff --git a/vm/vm.go b/vm/vm.go index bab46e0875..918a37e3df 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -315,7 +315,6 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid state: state, log: v.log, } - handle := cgo.NewHandle(context) defer handle.Delete() @@ -323,6 +322,7 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid if err != nil { return nil, nil, nil, nil, 0, err } + paidFeesOnL1Bytes, err := json.Marshal(paidFeesOnL1) if err != nil { return nil, nil, nil, nil, 0, err diff --git a/vm/vm_test.go b/vm/vm_test.go index 026d3801ea..04ff3fb8b0 100644 --- a/vm/vm_test.go +++ b/vm/vm_test.go @@ -36,11 +36,11 @@ func TestV0Call(t *testing.T) { require.NoError(t, encoder.RegisterType(reflect.TypeOf(core.Cairo0Class{}))) testState := core.NewState(txn) - require.NoError(t, testState.Update(0, &core.StateDiff{ + require.NoError(t, testState.Update(0, &core.StateUpdate{StateDiff: &core.StateDiff{ DeployedContracts: map[felt.Felt]*felt.Felt{ *contractAddr: classHash, }, - }, map[felt.Felt]core.Class{ + }}, map[felt.Felt]core.Class{ *classHash: simpleClass, })) @@ -54,12 +54,12 @@ func TestV0Call(t *testing.T) { require.NoError(t, err) assert.Equal(t, []*felt.Felt{&felt.Zero}, ret) - require.NoError(t, testState.Update(1, &core.StateDiff{ + require.NoError(t, testState.Update(1, &core.StateUpdate{StateDiff: &core.StateDiff{ StorageDiffs: map[felt.Felt]map[felt.Felt]*felt.Felt{ *contractAddr: { *utils.HexToFelt(t, "0x206f38f7e4f15e87567361213c28f235cccdaa1d7fd34c9db1dfe9489c6a091"): new(felt.Felt).SetUint64(1337), }, - }, + }}, }, nil)) ret, err = New(false, nil).Call(&CallInfo{ @@ -90,10 +90,10 @@ func TestV1Call(t *testing.T) { require.NoError(t, encoder.RegisterType(reflect.TypeOf(core.Cairo1Class{}))) testState := core.NewState(txn) - require.NoError(t, testState.Update(0, &core.StateDiff{ + require.NoError(t, testState.Update(0, &core.StateUpdate{StateDiff: &core.StateDiff{ DeployedContracts: map[felt.Felt]*felt.Felt{ *contractAddr: classHash, - }, + }}, }, map[felt.Felt]core.Class{ *classHash: simpleClass, })) @@ -114,12 +114,12 @@ func TestV1Call(t *testing.T) { require.NoError(t, err) assert.Equal(t, []*felt.Felt{&felt.Zero}, ret) - require.NoError(t, testState.Update(1, &core.StateDiff{ + require.NoError(t, testState.Update(1, &core.StateUpdate{StateDiff: &core.StateDiff{ StorageDiffs: map[felt.Felt]map[felt.Felt]*felt.Felt{ *contractAddr: { *storageLocation: new(felt.Felt).SetUint64(37), }, - }, + }}, }, nil)) ret, err = New(false, log).Call(&CallInfo{ @@ -152,10 +152,10 @@ func TestCall_MaxSteps(t *testing.T) { encoder.RegisterType(reflect.TypeOf(core.Cairo0Class{})) //nolint:errcheck testState := core.NewState(txn) - require.NoError(t, testState.Update(0, &core.StateDiff{ + require.NoError(t, testState.Update(0, &core.StateUpdate{StateDiff: &core.StateDiff{ DeployedContracts: map[felt.Felt]*felt.Felt{ *contractAddr: classHash, - }, + }}, }, map[felt.Felt]core.Class{ *classHash: simpleClass, }))