From 8f47d73c255de071a3bf33d9bebdd8eda1d92c9e Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Thu, 27 May 2021 19:01:01 -0400 Subject: [PATCH 01/10] refactor: queueOrigin type --- .../accounts/abi/bind/backends/simulated.go | 2 +- l2geth/core/state_transition.go | 6 ++--- l2geth/core/state_transition_ovm.go | 27 +++---------------- l2geth/core/types/gen_tx_meta_json.go | 6 ++--- l2geth/core/types/transaction.go | 16 +++++------ l2geth/core/types/transaction_meta.go | 16 +++++------ l2geth/core/types/transaction_meta_test.go | 9 +------ l2geth/interfaces.go | 2 +- l2geth/internal/ethapi/api.go | 14 +++++----- l2geth/miner/worker.go | 2 +- l2geth/rollup/sync_service.go | 11 +++----- 11 files changed, 35 insertions(+), 76 deletions(-) diff --git a/l2geth/accounts/abi/bind/backends/simulated.go b/l2geth/accounts/abi/bind/backends/simulated.go index 243491799533..68f65dbf145c 100644 --- a/l2geth/accounts/abi/bind/backends/simulated.go +++ b/l2geth/accounts/abi/bind/backends/simulated.go @@ -603,7 +603,7 @@ func (m callmsg) Data() []byte { return m.CallMsg.Data } func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender } func (m callmsg) L1BlockNumber() *big.Int { return m.CallMsg.L1BlockNumber } -func (m callmsg) QueueOrigin() *big.Int { return m.CallMsg.QueueOrigin } +func (m callmsg) QueueOrigin() types.QueueOrigin { return m.CallMsg.QueueOrigin } func (m callmsg) SignatureHashType() types.SignatureHashType { return m.CallMsg.SignatureHashType } // filterBackend implements filters.Backend to support filtering for logs without diff --git a/l2geth/core/state_transition.go b/l2geth/core/state_transition.go index d5e839a757dc..90ee60fad88a 100644 --- a/l2geth/core/state_transition.go +++ b/l2geth/core/state_transition.go @@ -77,7 +77,7 @@ type Message interface { Data() []byte L1MessageSender() *common.Address L1BlockNumber() *big.Int - QueueOrigin() *big.Int + QueueOrigin() types.QueueOrigin SignatureHashType() types.SignatureHashType } @@ -185,9 +185,7 @@ func (st *StateTransition) preCheck() error { if nonce < st.msg.Nonce() { if vm.UsingOVM { // The nonce never increments for L1ToL2 txs - qo := st.msg.QueueOrigin() - l1ToL2 := uint64(types.QueueOriginL1ToL2) - if qo != nil && qo.Uint64() == l1ToL2 { + if st.msg.QueueOrigin() == types.QueueOriginL1ToL2 { return st.buyGas() } } diff --git a/l2geth/core/state_transition_ovm.go b/l2geth/core/state_transition_ovm.go index adba0fb257df..f00e36867238 100644 --- a/l2geth/core/state_transition_ovm.go +++ b/l2geth/core/state_transition_ovm.go @@ -26,7 +26,7 @@ func toExecutionManagerRun(evm *vm.EVM, msg Message) (Message, error) { tx := ovmTransaction{ evm.Context.Time, msg.L1BlockNumber(), - uint8(msg.QueueOrigin().Uint64()), + uint8(msg.QueueOrigin()), *msg.L1MessageSender(), *msg.To(), big.NewInt(int64(msg.Gas())), @@ -74,7 +74,7 @@ func AsOvmMessage(tx *types.Transaction, signer types.Signer, decompressor commo // correct format when deserialized from the EVM events, see // rollup/sync_service.go. qo := msg.QueueOrigin() - if qo != nil && qo.Uint64() == uint64(types.QueueOriginL1ToL2) { + if qo == types.QueueOriginL1ToL2 { return msg, nil } @@ -104,7 +104,7 @@ func EncodeSimulatedMessage(msg Message, timestamp, blockNumber *big.Int, execut tx := ovmTransaction{ timestamp, blockNumber, - uint8(msg.QueueOrigin().Uint64()), + uint8(msg.QueueOrigin()), *msg.L1MessageSender(), *to, big.NewInt(int64(msg.Gas())), @@ -139,11 +139,6 @@ func modMessage( data []byte, gasLimit uint64, ) (Message, error) { - queueOrigin, err := getQueueOrigin(msg.QueueOrigin()) - if err != nil { - return nil, err - } - outmsg := types.NewMessage( from, to, @@ -155,23 +150,9 @@ func modMessage( false, msg.L1MessageSender(), msg.L1BlockNumber(), - queueOrigin, + msg.QueueOrigin(), msg.SignatureHashType(), ) return outmsg, nil } - -func getQueueOrigin( - queueOrigin *big.Int, -) (types.QueueOrigin, error) { - if queueOrigin.Cmp(big.NewInt(0)) == 0 { - return types.QueueOriginSequencer, nil - } else if queueOrigin.Cmp(big.NewInt(1)) == 0 { - return types.QueueOriginL1ToL2, nil - } else if queueOrigin.Cmp(big.NewInt(2)) == 0 { - return types.QueueOriginL1ToL2, nil - } else { - return types.QueueOriginSequencer, fmt.Errorf("invalid queue origin: %d", queueOrigin) - } -} diff --git a/l2geth/core/types/gen_tx_meta_json.go b/l2geth/core/types/gen_tx_meta_json.go index 5bf2f763f36e..cff94e45fe14 100644 --- a/l2geth/core/types/gen_tx_meta_json.go +++ b/l2geth/core/types/gen_tx_meta_json.go @@ -16,7 +16,7 @@ func (t TransactionMeta) MarshalJSON() ([]byte, error) { L1BlockNumber *big.Int `json:"l1BlockNumber"` L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` SignatureHashType SignatureHashType `json:"signatureHashType" gencodec:"required"` - QueueOrigin *big.Int `json:"queueOrigin" gencodec:"required"` + QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` Index *uint64 `json:"index" gencodec:"required"` } var enc TransactionMeta @@ -34,7 +34,7 @@ func (t *TransactionMeta) UnmarshalJSON(input []byte) error { L1BlockNumber *big.Int `json:"l1BlockNumber"` L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` SignatureHashType *SignatureHashType `json:"signatureHashType" gencodec:"required"` - QueueOrigin *big.Int `json:"queueOrigin" gencodec:"required"` + QueueOrigin *QueueOrigin `json:"queueOrigin" gencodec:"required"` Index *uint64 `json:"index" gencodec:"required"` } var dec TransactionMeta @@ -55,7 +55,7 @@ func (t *TransactionMeta) UnmarshalJSON(input []byte) error { if dec.QueueOrigin == nil { return errors.New("missing required field 'queueOrigin' for TransactionMeta") } - t.QueueOrigin = dec.QueueOrigin + t.QueueOrigin = *dec.QueueOrigin if dec.Index == nil { return errors.New("missing required field 'index' for TransactionMeta") } diff --git a/l2geth/core/types/transaction.go b/l2geth/core/types/transaction.go index a3fc9874acf6..ec194fd935f7 100644 --- a/l2geth/core/types/transaction.go +++ b/l2geth/core/types/transaction.go @@ -270,13 +270,9 @@ func (tx *Transaction) L1BlockNumber() *big.Int { return &l1BlockNumber } -// QueueOrigin returns the Queue Origin of the transaction if it exists. -func (tx *Transaction) QueueOrigin() *big.Int { - if tx.meta.QueueOrigin == nil { - return nil - } - queueOrigin := *tx.meta.QueueOrigin - return &queueOrigin +// QueueOrigin returns the Queue Origin of the transaction +func (tx *Transaction) QueueOrigin() QueueOrigin { + return tx.meta.QueueOrigin } // Hash hashes the RLP encoding of tx. @@ -537,7 +533,7 @@ type Message struct { l1MessageSender *common.Address l1BlockNumber *big.Int signatureHashType SignatureHashType - queueOrigin *big.Int + queueOrigin QueueOrigin } func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin, signatureHashType SignatureHashType) Message { @@ -554,7 +550,7 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b l1BlockNumber: l1BlockNumber, l1MessageSender: l1MessageSender, signatureHashType: signatureHashType, - queueOrigin: big.NewInt(int64(queueOrigin)), + queueOrigin: queueOrigin, } } @@ -570,4 +566,4 @@ func (m Message) CheckNonce() bool { return m.checkNonce } func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender } func (m Message) L1BlockNumber() *big.Int { return m.l1BlockNumber } func (m Message) SignatureHashType() SignatureHashType { return m.signatureHashType } -func (m Message) QueueOrigin() *big.Int { return m.queueOrigin } +func (m Message) QueueOrigin() QueueOrigin { return m.queueOrigin } diff --git a/l2geth/core/types/transaction_meta.go b/l2geth/core/types/transaction_meta.go index a475c53decc7..9018f2b563d9 100644 --- a/l2geth/core/types/transaction_meta.go +++ b/l2geth/core/types/transaction_meta.go @@ -27,7 +27,7 @@ type TransactionMeta struct { L1Timestamp uint64 `json:"l1Timestamp"` L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` SignatureHashType SignatureHashType `json:"signatureHashType" gencodec:"required"` - QueueOrigin *big.Int `json:"queueOrigin" gencodec:"required"` + QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` // The canonical transaction chain index Index *uint64 `json:"index" gencodec:"required"` // The queue index, nil for queue origin sequencer transactions @@ -42,7 +42,7 @@ func NewTransactionMeta(l1BlockNumber *big.Int, l1timestamp uint64, l1MessageSen L1Timestamp: l1timestamp, L1MessageSender: l1MessageSender, SignatureHashType: sighashType, - QueueOrigin: big.NewInt(int64(queueOrigin)), + QueueOrigin: queueOrigin, Index: index, QueueIndex: queueIndex, RawTransaction: rawTransaction, @@ -94,7 +94,7 @@ func TxMetaDecode(input []byte) (*TransactionMeta, error) { } if !isNullValue(qo) { queueOrigin := new(big.Int).SetBytes(qo) - meta.QueueOrigin = queueOrigin + meta.QueueOrigin = QueueOrigin(queueOrigin.Uint64()) } l, err := common.ReadVarBytes(b, 0, 1024, "L1Timestamp") @@ -161,13 +161,9 @@ func TxMetaEncode(meta *TransactionMeta) []byte { } queueOrigin := meta.QueueOrigin - if queueOrigin == nil { - common.WriteVarBytes(b, 0, getNullValue()) - } else { - q := new(bytes.Buffer) - binary.Write(q, binary.LittleEndian, queueOrigin.Bytes()) - common.WriteVarBytes(b, 0, q.Bytes()) - } + q := new(bytes.Buffer) + binary.Write(q, binary.LittleEndian, queueOrigin) + common.WriteVarBytes(b, 0, q.Bytes()) l := new(bytes.Buffer) binary.Write(l, binary.LittleEndian, &meta.L1Timestamp) diff --git a/l2geth/core/types/transaction_meta_test.go b/l2geth/core/types/transaction_meta_test.go index 6471b5f77614..554a39c16907 100644 --- a/l2geth/core/types/transaction_meta_test.go +++ b/l2geth/core/types/transaction_meta_test.go @@ -153,14 +153,7 @@ func isTxMetaEqual(meta1 *TransactionMeta, meta2 *TransactionMeta) bool { return false } - if meta1.QueueOrigin == nil || meta2.QueueOrigin == nil { - // Note: this only works because it is the final comparison - if meta1.QueueOrigin == nil && meta2.QueueOrigin == nil { - return true - } - } - - if !bytes.Equal(meta1.QueueOrigin.Bytes(), meta2.QueueOrigin.Bytes()) { + if meta1.QueueOrigin != meta2.QueueOrigin { return false } diff --git a/l2geth/interfaces.go b/l2geth/interfaces.go index 50bde19ddf8c..cbfc312f8f62 100644 --- a/l2geth/interfaces.go +++ b/l2geth/interfaces.go @@ -122,7 +122,7 @@ type CallMsg struct { L1MessageSender *common.Address L1BlockNumber *big.Int - QueueOrigin *big.Int + QueueOrigin types.QueueOrigin SignatureHashType types.SignatureHashType } diff --git a/l2geth/internal/ethapi/api.go b/l2geth/internal/ethapi/api.go index 2828d83707bd..9f07e6ed1b9a 100644 --- a/l2geth/internal/ethapi/api.go +++ b/l2geth/internal/ethapi/api.go @@ -1358,13 +1358,11 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber if meta.L1BlockNumber != nil { result.L1BlockNumber = (*hexutil.Big)(meta.L1BlockNumber) } - if meta.QueueOrigin != nil { - switch meta.QueueOrigin.Uint64() { - case uint64(types.QueueOriginSequencer): - result.QueueOrigin = "sequencer" - case uint64(types.QueueOriginL1ToL2): - result.QueueOrigin = "l1" - } + switch meta.QueueOrigin { + case types.QueueOriginSequencer: + result.QueueOrigin = "sequencer" + case types.QueueOriginL1ToL2: + result.QueueOrigin = "l1" } if meta.Index != nil { @@ -2174,7 +2172,7 @@ func (api *PrivateDebugAPI) IngestTransactions(txs []*RPCTransaction) error { L1Timestamp: l1Timestamp, L1MessageSender: tx.L1TxOrigin, SignatureHashType: sighashType, - QueueOrigin: big.NewInt(int64(queueOrigin)), + QueueOrigin: queueOrigin, Index: (*uint64)(tx.Index), QueueIndex: (*uint64)(tx.QueueIndex), RawTransaction: rawTransaction, diff --git a/l2geth/miner/worker.go b/l2geth/miner/worker.go index 2c9a0a177997..e71580ea13d3 100644 --- a/l2geth/miner/worker.go +++ b/l2geth/miner/worker.go @@ -869,7 +869,7 @@ func (w *worker) commitNewTx(tx *types.Transaction) error { // transactions as the timestamp cannot be malleated if parent.Time() > tx.L1Timestamp() { log.Error("Monotonicity violation", "index", num) - if tx.QueueOrigin().Uint64() == uint64(types.QueueOriginSequencer) { + if tx.QueueOrigin() == types.QueueOriginSequencer { tx.SetL1Timestamp(parent.Time()) prev := parent.Transactions() if len(prev) == 1 { diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index b3f831559a79..c382a59e65f6 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -649,7 +649,7 @@ func (s *SyncService) applyTransactionToTip(tx *types.Transaction) error { // Queue Origin L1 to L2 transactions must have a timestamp that is set by // the L1 block that holds the transaction. This should never happen but is // a sanity check to prevent fraudulent execution. - if tx.QueueOrigin().Uint64() == uint64(types.QueueOriginL1ToL2) { + if tx.QueueOrigin() == types.QueueOriginL1ToL2 { if tx.L1Timestamp() == 0 { return fmt.Errorf("Queue origin L1 to L2 transaction without a timestamp: %s", tx.Hash().Hex()) } @@ -676,7 +676,7 @@ func (s *SyncService) applyTransactionToTip(tx *types.Transaction) error { bn := tx.L1BlockNumber() s.SetLatestL1Timestamp(ts) s.SetLatestL1BlockNumber(bn.Uint64()) - log.Debug("Updating OVM context based on new transaction", "timestamp", ts, "blocknumber", bn.Uint64(), "queue-origin", tx.QueueOrigin().Uint64()) + log.Debug("Updating OVM context based on new transaction", "timestamp", ts, "blocknumber", bn.Uint64(), "queue-origin", tx.QueueOrigin()) } else if tx.L1Timestamp() < s.GetLatestL1Timestamp() { log.Error("Timestamp monotonicity violation", "hash", tx.Hash().Hex()) } @@ -782,11 +782,8 @@ func (s *SyncService) ValidateAndApplySequencerTransaction(tx *types.Transaction log.Trace("Sequencer transaction validation", "hash", tx.Hash().Hex()) qo := tx.QueueOrigin() - if qo == nil { - return errors.New("invalid transaction with no queue origin") - } - if qo.Uint64() != uint64(types.QueueOriginSequencer) { - return fmt.Errorf("invalid transaction with queue origin %d", qo.Uint64()) + if qo != types.QueueOriginSequencer { + return fmt.Errorf("invalid transaction with queue origin %d", qo) } err := s.txpool.ValidateTx(tx) if err != nil { From 99c7efd65fa36da43d2f4ea44cebde427c80e3f8 Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Thu, 27 May 2021 19:39:55 -0400 Subject: [PATCH 02/10] Convert queueOrigin to uint8 in encode --- l2geth/core/types/transaction_meta.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l2geth/core/types/transaction_meta.go b/l2geth/core/types/transaction_meta.go index 9018f2b563d9..29be8f5b45c2 100644 --- a/l2geth/core/types/transaction_meta.go +++ b/l2geth/core/types/transaction_meta.go @@ -160,7 +160,7 @@ func TxMetaEncode(meta *TransactionMeta) []byte { common.WriteVarBytes(b, 0, l.Bytes()) } - queueOrigin := meta.QueueOrigin + queueOrigin := uint8(meta.QueueOrigin) q := new(bytes.Buffer) binary.Write(q, binary.LittleEndian, queueOrigin) common.WriteVarBytes(b, 0, q.Bytes()) From 8c4ae2a1c16dbcbcb3a630fb185a13990dee502c Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Thu, 27 May 2021 19:42:14 -0400 Subject: [PATCH 03/10] Add changeset --- .changeset/heavy-planets-return.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/heavy-planets-return.md diff --git a/.changeset/heavy-planets-return.md b/.changeset/heavy-planets-return.md new file mode 100644 index 000000000000..c69ceaf05bc6 --- /dev/null +++ b/.changeset/heavy-planets-return.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/l2geth': patch +--- + +Update queueOrigin type From 3a9cb1b2b6e50681e7e87b009c74204cf64ef4f7 Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Thu, 27 May 2021 20:12:17 -0400 Subject: [PATCH 04/10] Regenerate json marshall --- l2geth/core/types/gen_tx_json.go | 8 ++++---- l2geth/core/types/gen_tx_meta_json.go | 20 ++++++++++++++++++++ l2geth/core/types/transaction.go | 4 ++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/l2geth/core/types/gen_tx_json.go b/l2geth/core/types/gen_tx_json.go index f8638522b070..e676058ecc4b 100644 --- a/l2geth/core/types/gen_tx_json.go +++ b/l2geth/core/types/gen_tx_json.go @@ -13,8 +13,8 @@ import ( var _ = (*txdataMarshaling)(nil) -// TransactionMarshalJSON marshals as JSON. -func (t txdata) TransactionMarshalJSON() ([]byte, error) { +// MarshalJSON marshals as JSON. +func (t txdata) MarshalJSON() ([]byte, error) { type txdata struct { AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"` Price *hexutil.Big `json:"gasPrice" gencodec:"required"` @@ -41,8 +41,8 @@ func (t txdata) TransactionMarshalJSON() ([]byte, error) { return json.Marshal(&enc) } -// TransactionUnmarshalJSON unmarshals from JSON. -func (t *txdata) TransactionUnmarshalJSON(input []byte) error { +// UnmarshalJSON unmarshals from JSON. +func (t *txdata) UnmarshalJSON(input []byte) error { type txdata struct { AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` Price *hexutil.Big `json:"gasPrice" gencodec:"required"` diff --git a/l2geth/core/types/gen_tx_meta_json.go b/l2geth/core/types/gen_tx_meta_json.go index cff94e45fe14..88543549ff3e 100644 --- a/l2geth/core/types/gen_tx_meta_json.go +++ b/l2geth/core/types/gen_tx_meta_json.go @@ -14,17 +14,23 @@ import ( func (t TransactionMeta) MarshalJSON() ([]byte, error) { type TransactionMeta struct { L1BlockNumber *big.Int `json:"l1BlockNumber"` + L1Timestamp uint64 `json:"l1Timestamp"` L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` SignatureHashType SignatureHashType `json:"signatureHashType" gencodec:"required"` QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` Index *uint64 `json:"index" gencodec:"required"` + QueueIndex *uint64 `json:"queueIndex" gencodec:"required"` + RawTransaction []byte `json:"rawTransaction" gencodec:"required"` } var enc TransactionMeta enc.L1BlockNumber = t.L1BlockNumber + enc.L1Timestamp = t.L1Timestamp enc.L1MessageSender = t.L1MessageSender enc.SignatureHashType = t.SignatureHashType enc.QueueOrigin = t.QueueOrigin enc.Index = t.Index + enc.QueueIndex = t.QueueIndex + enc.RawTransaction = t.RawTransaction return json.Marshal(&enc) } @@ -32,10 +38,13 @@ func (t TransactionMeta) MarshalJSON() ([]byte, error) { func (t *TransactionMeta) UnmarshalJSON(input []byte) error { type TransactionMeta struct { L1BlockNumber *big.Int `json:"l1BlockNumber"` + L1Timestamp *uint64 `json:"l1Timestamp"` L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` SignatureHashType *SignatureHashType `json:"signatureHashType" gencodec:"required"` QueueOrigin *QueueOrigin `json:"queueOrigin" gencodec:"required"` Index *uint64 `json:"index" gencodec:"required"` + QueueIndex *uint64 `json:"queueIndex" gencodec:"required"` + RawTransaction []byte `json:"rawTransaction" gencodec:"required"` } var dec TransactionMeta if err := json.Unmarshal(input, &dec); err != nil { @@ -44,6 +53,9 @@ func (t *TransactionMeta) UnmarshalJSON(input []byte) error { if dec.L1BlockNumber != nil { t.L1BlockNumber = dec.L1BlockNumber } + if dec.L1Timestamp != nil { + t.L1Timestamp = *dec.L1Timestamp + } if dec.L1MessageSender == nil { return errors.New("missing required field 'l1MessageSender' for TransactionMeta") } @@ -60,5 +72,13 @@ func (t *TransactionMeta) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'index' for TransactionMeta") } t.Index = dec.Index + if dec.QueueIndex == nil { + return errors.New("missing required field 'queueIndex' for TransactionMeta") + } + t.QueueIndex = dec.QueueIndex + if dec.RawTransaction == nil { + return errors.New("missing required field 'rawTransaction' for TransactionMeta") + } + t.RawTransaction = dec.RawTransaction return nil } diff --git a/l2geth/core/types/transaction.go b/l2geth/core/types/transaction.go index ec194fd935f7..26a534f8d0a8 100644 --- a/l2geth/core/types/transaction.go +++ b/l2geth/core/types/transaction.go @@ -196,12 +196,12 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error { // MarshalJSON encodes the web3 RPC transaction format. func (tx *Transaction) MarshalJSON() ([]byte, error) { - return tx.data.TransactionMarshalJSON() + return tx.data.MarshalJSON() } // UnmarshalJSON decodes the web3 RPC transaction format. func (tx *Transaction) UnmarshalJSON(input []byte) error { - err := tx.data.TransactionUnmarshalJSON(input) + err := tx.data.UnmarshalJSON(input) if err != nil { return err } From cdad7ebc529af7d98837643caa9fac10329e5e69 Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Thu, 27 May 2021 23:37:32 -0400 Subject: [PATCH 05/10] style: combine lines --- l2geth/core/state_transition_ovm.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/l2geth/core/state_transition_ovm.go b/l2geth/core/state_transition_ovm.go index f00e36867238..4506bd080ce4 100644 --- a/l2geth/core/state_transition_ovm.go +++ b/l2geth/core/state_transition_ovm.go @@ -73,8 +73,7 @@ func AsOvmMessage(tx *types.Transaction, signer types.Signer, decompressor commo // sequencer entrypoint. The calldata is expected to be in the // correct format when deserialized from the EVM events, see // rollup/sync_service.go. - qo := msg.QueueOrigin() - if qo == types.QueueOriginL1ToL2 { + if msg.QueueOrigin() == types.QueueOriginL1ToL2 { return msg, nil } From 9b86c9ebb0871fdf193870bc4aba9b5e07b3aa81 Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Thu, 27 May 2021 23:41:26 -0400 Subject: [PATCH 06/10] Add Stringer for QueueOrigin --- l2geth/core/types/transaction_meta.go | 11 +++++++++++ l2geth/internal/ethapi/api.go | 8 ++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/l2geth/core/types/transaction_meta.go b/l2geth/core/types/transaction_meta.go index 29be8f5b45c2..ef8b489bdd20 100644 --- a/l2geth/core/types/transaction_meta.go +++ b/l2geth/core/types/transaction_meta.go @@ -20,6 +20,17 @@ const ( QueueOriginL1ToL2 QueueOrigin = 1 ) +func (q QueueOrigin) String() string { + switch q { + case QueueOriginSequencer: + return "sequencer" + case QueueOriginL1ToL2: + return "l1" + default: + return "" + } +} + //go:generate gencodec -type TransactionMeta -out gen_tx_meta_json.go type TransactionMeta struct { diff --git a/l2geth/internal/ethapi/api.go b/l2geth/internal/ethapi/api.go index 9f07e6ed1b9a..9f90347b10e6 100644 --- a/l2geth/internal/ethapi/api.go +++ b/l2geth/internal/ethapi/api.go @@ -1358,12 +1358,8 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber if meta.L1BlockNumber != nil { result.L1BlockNumber = (*hexutil.Big)(meta.L1BlockNumber) } - switch meta.QueueOrigin { - case types.QueueOriginSequencer: - result.QueueOrigin = "sequencer" - case types.QueueOriginL1ToL2: - result.QueueOrigin = "l1" - } + + result.QueueOrigin = fmt.Sprint(meta.QueueOrigin) if meta.Index != nil { index := (hexutil.Uint64)(*meta.Index) From 7f47294c4fafe5259f1ad7f5cff80246bfa9bfd3 Mon Sep 17 00:00:00 2001 From: Karl Floersch Date: Fri, 28 May 2021 17:33:36 -0400 Subject: [PATCH 07/10] Turn QueueOrigin into uint8 --- l2geth/core/types/transaction_meta.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/l2geth/core/types/transaction_meta.go b/l2geth/core/types/transaction_meta.go index ef8b489bdd20..32493fc96c50 100644 --- a/l2geth/core/types/transaction_meta.go +++ b/l2geth/core/types/transaction_meta.go @@ -12,7 +12,7 @@ import ( "github.com/ethereum/go-ethereum/common" ) -type QueueOrigin int64 +type QueueOrigin uint8 const ( // Possible `queue_origin` values @@ -171,7 +171,7 @@ func TxMetaEncode(meta *TransactionMeta) []byte { common.WriteVarBytes(b, 0, l.Bytes()) } - queueOrigin := uint8(meta.QueueOrigin) + queueOrigin := meta.QueueOrigin q := new(bytes.Buffer) binary.Write(q, binary.LittleEndian, queueOrigin) common.WriteVarBytes(b, 0, q.Bytes()) From bf143e086cdac4b724e6b0270c69c9d8c8f648c0 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Wed, 2 Jun 2021 14:07:16 -0700 Subject: [PATCH 08/10] l2geth: gen tx meta fix --- l2geth/core/types/gen_tx_meta_json.go | 30 +++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/l2geth/core/types/gen_tx_meta_json.go b/l2geth/core/types/gen_tx_meta_json.go index 89950116809a..0f99ba918546 100644 --- a/l2geth/core/types/gen_tx_meta_json.go +++ b/l2geth/core/types/gen_tx_meta_json.go @@ -13,14 +13,13 @@ import ( // MarshalJSON marshals as JSON. func (t TransactionMeta) MarshalJSON() ([]byte, error) { type TransactionMeta struct { - L1BlockNumber *big.Int `json:"l1BlockNumber"` - L1Timestamp uint64 `json:"l1Timestamp"` - L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` - SignatureHashType SignatureHashType `json:"signatureHashType" gencodec:"required"` - QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` - Index *uint64 `json:"index" gencodec:"required"` - QueueIndex *uint64 `json:"queueIndex" gencodec:"required"` - RawTransaction []byte `json:"rawTransaction" gencodec:"required"` + L1BlockNumber *big.Int `json:"l1BlockNumber"` + L1Timestamp uint64 `json:"l1Timestamp"` + L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` + QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` + Index *uint64 `json:"index" gencodec:"required"` + QueueIndex *uint64 `json:"queueIndex" gencodec:"required"` + RawTransaction []byte `json:"rawTransaction" gencodec:"required"` } var enc TransactionMeta enc.L1BlockNumber = t.L1BlockNumber @@ -36,14 +35,13 @@ func (t TransactionMeta) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (t *TransactionMeta) UnmarshalJSON(input []byte) error { type TransactionMeta struct { - L1BlockNumber *big.Int `json:"l1BlockNumber"` - L1Timestamp *uint64 `json:"l1Timestamp"` - L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` - SignatureHashType *SignatureHashType `json:"signatureHashType" gencodec:"required"` - QueueOrigin *QueueOrigin `json:"queueOrigin" gencodec:"required"` - Index *uint64 `json:"index" gencodec:"required"` - QueueIndex *uint64 `json:"queueIndex" gencodec:"required"` - RawTransaction []byte `json:"rawTransaction" gencodec:"required"` + L1BlockNumber *big.Int `json:"l1BlockNumber"` + L1Timestamp *uint64 `json:"l1Timestamp"` + L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` + QueueOrigin *QueueOrigin `json:"queueOrigin" gencodec:"required"` + Index *uint64 `json:"index" gencodec:"required"` + QueueIndex *uint64 `json:"queueIndex" gencodec:"required"` + RawTransaction []byte `json:"rawTransaction" gencodec:"required"` } var dec TransactionMeta if err := json.Unmarshal(input, &dec); err != nil { From eeabe1f1bec70cb161eb8376c3e98193a3924b1e Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Wed, 2 Jun 2021 14:11:21 -0700 Subject: [PATCH 09/10] l2geth: gen tx meta fix --- l2geth/core/types/transaction_meta_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/l2geth/core/types/transaction_meta_test.go b/l2geth/core/types/transaction_meta_test.go index 82bffd9e8bcc..ec630d7bdcd3 100644 --- a/l2geth/core/types/transaction_meta_test.go +++ b/l2geth/core/types/transaction_meta_test.go @@ -112,10 +112,6 @@ func isTxMetaEqual(meta1 *TransactionMeta, meta2 *TransactionMeta) bool { } } - if meta1.SignatureHashType != meta2.SignatureHashType { - return false - } - if meta1.QueueOrigin != meta2.QueueOrigin { return false } From 351ad041ef7dd3a8f8c5141ce65f355dc660f414 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Wed, 2 Jun 2021 15:46:14 -0700 Subject: [PATCH 10/10] lint --- .../accounts/abi/bind/backends/simulated.go | 6 ++--- l2geth/core/types/transaction.go | 18 +++++++-------- l2geth/core/types/transaction_meta.go | 22 +++++++++---------- l2geth/interfaces.go | 6 ++--- l2geth/internal/ethapi/api.go | 14 ++++++------ 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/l2geth/accounts/abi/bind/backends/simulated.go b/l2geth/accounts/abi/bind/backends/simulated.go index f7a7eed28c93..83701e91f4d5 100644 --- a/l2geth/accounts/abi/bind/backends/simulated.go +++ b/l2geth/accounts/abi/bind/backends/simulated.go @@ -601,9 +601,9 @@ func (m callmsg) Gas() uint64 { return m.CallMsg.Gas } func (m callmsg) Value() *big.Int { return m.CallMsg.Value } func (m callmsg) Data() []byte { return m.CallMsg.Data } -func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender } -func (m callmsg) L1BlockNumber() *big.Int { return m.CallMsg.L1BlockNumber } -func (m callmsg) QueueOrigin() types.QueueOrigin { return m.CallMsg.QueueOrigin } +func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender } +func (m callmsg) L1BlockNumber() *big.Int { return m.CallMsg.L1BlockNumber } +func (m callmsg) QueueOrigin() types.QueueOrigin { return m.CallMsg.QueueOrigin } // filterBackend implements filters.Backend to support filtering for logs without // taking bloom-bits acceleration structures into account. diff --git a/l2geth/core/types/transaction.go b/l2geth/core/types/transaction.go index 2f3744bedd4e..bb016fb22083 100644 --- a/l2geth/core/types/transaction.go +++ b/l2geth/core/types/transaction.go @@ -512,9 +512,9 @@ type Message struct { data []byte checkNonce bool - l1MessageSender *common.Address - l1BlockNumber *big.Int - queueOrigin QueueOrigin + l1MessageSender *common.Address + l1BlockNumber *big.Int + queueOrigin QueueOrigin } func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin) Message { @@ -528,9 +528,9 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b data: data, checkNonce: checkNonce, - l1BlockNumber: l1BlockNumber, - l1MessageSender: l1MessageSender, - queueOrigin: queueOrigin, + l1BlockNumber: l1BlockNumber, + l1MessageSender: l1MessageSender, + queueOrigin: queueOrigin, } } @@ -543,6 +543,6 @@ func (m Message) Nonce() uint64 { return m.nonce } func (m Message) Data() []byte { return m.data } func (m Message) CheckNonce() bool { return m.checkNonce } -func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender } -func (m Message) L1BlockNumber() *big.Int { return m.l1BlockNumber } -func (m Message) QueueOrigin() QueueOrigin { return m.queueOrigin } \ No newline at end of file +func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender } +func (m Message) L1BlockNumber() *big.Int { return m.l1BlockNumber } +func (m Message) QueueOrigin() QueueOrigin { return m.queueOrigin } diff --git a/l2geth/core/types/transaction_meta.go b/l2geth/core/types/transaction_meta.go index 3b1a2595e0e4..7f68e6530129 100644 --- a/l2geth/core/types/transaction_meta.go +++ b/l2geth/core/types/transaction_meta.go @@ -34,10 +34,10 @@ func (q QueueOrigin) String() string { //go:generate gencodec -type TransactionMeta -out gen_tx_meta_json.go type TransactionMeta struct { - L1BlockNumber *big.Int `json:"l1BlockNumber"` - L1Timestamp uint64 `json:"l1Timestamp"` - L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` - QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` + L1BlockNumber *big.Int `json:"l1BlockNumber"` + L1Timestamp uint64 `json:"l1Timestamp"` + L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"` + QueueOrigin QueueOrigin `json:"queueOrigin" gencodec:"required"` // The canonical transaction chain index Index *uint64 `json:"index" gencodec:"required"` // The queue index, nil for queue origin sequencer transactions @@ -48,13 +48,13 @@ type TransactionMeta struct { // NewTransactionMeta creates a TransactionMeta func NewTransactionMeta(l1BlockNumber *big.Int, l1timestamp uint64, l1MessageSender *common.Address, queueOrigin QueueOrigin, index *uint64, queueIndex *uint64, rawTransaction []byte) *TransactionMeta { return &TransactionMeta{ - L1BlockNumber: l1BlockNumber, - L1Timestamp: l1timestamp, - L1MessageSender: l1MessageSender, - QueueOrigin: queueOrigin, - Index: index, - QueueIndex: queueIndex, - RawTransaction: rawTransaction, + L1BlockNumber: l1BlockNumber, + L1Timestamp: l1timestamp, + L1MessageSender: l1MessageSender, + QueueOrigin: queueOrigin, + Index: index, + QueueIndex: queueIndex, + RawTransaction: rawTransaction, } } diff --git a/l2geth/interfaces.go b/l2geth/interfaces.go index 930458f933f3..aaf10f31c5d7 100644 --- a/l2geth/interfaces.go +++ b/l2geth/interfaces.go @@ -120,9 +120,9 @@ type CallMsg struct { Value *big.Int // amount of wei sent along with the call Data []byte // input data, usually an ABI-encoded contract method invocation - L1MessageSender *common.Address - L1BlockNumber *big.Int - QueueOrigin types.QueueOrigin + L1MessageSender *common.Address + L1BlockNumber *big.Int + QueueOrigin types.QueueOrigin } // A ContractCaller provides contract calls, essentially transactions that are executed by diff --git a/l2geth/internal/ethapi/api.go b/l2geth/internal/ethapi/api.go index fc09106813d1..17a0dfc8e491 100644 --- a/l2geth/internal/ethapi/api.go +++ b/l2geth/internal/ethapi/api.go @@ -2151,13 +2151,13 @@ func (api *PrivateDebugAPI) IngestTransactions(txs []*RPCTransaction) error { } meta := types.TransactionMeta{ - L1BlockNumber: l1BlockNumber, - L1Timestamp: l1Timestamp, - L1MessageSender: tx.L1TxOrigin, - QueueOrigin: queueOrigin, - Index: (*uint64)(tx.Index), - QueueIndex: (*uint64)(tx.QueueIndex), - RawTransaction: rawTransaction, + L1BlockNumber: l1BlockNumber, + L1Timestamp: l1Timestamp, + L1MessageSender: tx.L1TxOrigin, + QueueOrigin: queueOrigin, + Index: (*uint64)(tx.Index), + QueueIndex: (*uint64)(tx.QueueIndex), + RawTransaction: rawTransaction, } transaction.SetTransactionMeta(&meta) transactions[i] = transaction