From ee3941038f4eced70b06b040a43b4ed6e425c868 Mon Sep 17 00:00:00 2001 From: Will Hester Date: Tue, 4 Jun 2024 11:41:22 +0100 Subject: [PATCH] stashing --- go/ethadapter/geth_rpc_client.go | 7 ++-- .../mgmtcontractlib/mgmt_contract_lib.go | 37 +++++++++++++------ go/host/l1/publisher.go | 37 +++++++++++++++++-- go/wallet/wallet.go | 2 +- integration/ethereummock/node.go | 8 ++-- 5 files changed, 67 insertions(+), 24 deletions(-) diff --git a/go/ethadapter/geth_rpc_client.go b/go/ethadapter/geth_rpc_client.go index 6d9d77f22f..1cd5aa60eb 100644 --- a/go/ethadapter/geth_rpc_client.go +++ b/go/ethadapter/geth_rpc_client.go @@ -266,9 +266,9 @@ func (e *gethRPCClient) PrepareTransactionToSend(ctx context.Context, txData typ func (e *gethRPCClient) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, nonce uint64, retryNumber int) (types.TxData, error) { switch tx := txData.(type) { case *types.LegacyTx: - return e.prepareLegacyTxToRetry(ctx, tx, from, nonce, 0) + return e.prepareLegacyTxToRetry(ctx, tx, from, nonce, retryNumber) case *types.BlobTx: - return e.prepareBlobTxToRetry(ctx, tx, from, nonce, 0) + return e.prepareBlobTxToRetry(ctx, tx, from, nonce, retryNumber) default: return nil, fmt.Errorf("unsupported transaction type: %T", tx) } @@ -346,13 +346,12 @@ func (e *gethRPCClient) prepareBlobTxToRetry(ctx context.Context, txData types.T return nil, fmt.Errorf("could not estimate gas - %w", err) } - //TODO calculate base fee cap blobBaseFee := big.NewInt(1) blobFeeCap := calcBlobFeeCap(blobBaseFee) //FIXME from config - chainId, _ := uint256.FromBig(unEstimatedTx.ChainId()) + chainId, _ := uint256.FromBig(big.NewInt(1337)) return &types.BlobTx{ ChainID: chainId, diff --git a/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go b/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go index fe4245b29d..3e074da9e0 100644 --- a/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go +++ b/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go @@ -91,22 +91,37 @@ func (c *contractLibImpl) DecodeTx(tx *types.Transaction) ethadapter.L1Transacti contractCallData := map[string]interface{}{} switch method.Name { case AddRollupMethod: - sidecar := tx.BlobTxSidecar() - blobs := sidecar.Blobs - var rollupData []byte - - for _, blob := range blobs { - rollupData = append(rollupData, blob[:]...) + //TODO clean this up + if tx.Type() == types.BlobTxType { + sidecar := tx.BlobTxSidecar() + blobs := sidecar.Blobs + var rollupData []byte + + for _, blob := range blobs { + rollupData = append(rollupData, blob[:]...) + } + + // TODO handle metadata + var encodedRollup common.EncodedRollup + if err := rlp.DecodeBytes(rollupData, &encodedRollup); err != nil { + panic(err) + } + + return ðadapter.L1RollupTx{ + Rollup: encodedRollup, + } } - - // TODO handle metadata - var encodedRollup common.EncodedRollup - if err := rlp.DecodeBytes(rollupData, &encodedRollup); err != nil { + if err := method.Inputs.UnpackIntoMap(contractCallData, tx.Data()[4:]); err != nil { panic(err) } + callData, found := contractCallData["_rollupData"] + if !found { + panic("call data not found for rollupData") + } + rollup := Base64DecodeFromString(callData.(string)) return ðadapter.L1RollupTx{ - Rollup: encodedRollup, + Rollup: rollup, } case RespondSecretMethod: diff --git a/go/host/l1/publisher.go b/go/host/l1/publisher.go index 840c61c2e2..92de7fe77d 100644 --- a/go/host/l1/publisher.go +++ b/go/host/l1/publisher.go @@ -1,9 +1,13 @@ package l1 import ( + "bytes" "context" + "encoding/hex" "encoding/json" "fmt" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/rlp" "math/big" "sync" "time" @@ -271,7 +275,6 @@ func (p *Publisher) PublishRollup(producedRollup *common.ExtRollup) { p.logger.Trace("Sending transaction to publish rollup", "rollup_header", headerLog, log.RollupHashKey, producedRollup.Header.Hash(), "batches_len", len(producedRollup.BatchPayloads)) } - //rollupTx := p.mgmtContractLib.CreateRollup(tx) rollupBlobTx, err := p.mgmtContractLib.CreateBlobRollup(tx) if err != nil { p.logger.Error("Could not create rollup blobs", log.RollupHashKey, producedRollup.Hash(), log.ErrKey, err) @@ -412,17 +415,43 @@ func (p *Publisher) publishTransaction(tx types.TxData) error { return errors.Wrap(err, "could not estimate gas/gas price for L1 tx") } - //FIXME here - //FIXME here could not request secret from L1: could not sign L1 tx: transaction type not supported" signedTx, err := p.hostWallet.SignTransaction(tx) if err != nil { return errors.Wrap(err, "could not sign L1 tx") } + blobTx, ok := tx.(*types.BlobTx) + + if ok { + println(blobTx) + println("ChainID:", signedTx.ChainId().String()) + println("Nonce:", signedTx.Nonce()) + println("GasTipCap:", signedTx.GasTipCap().String()) + println("GasFeeCap:", signedTx.GasFeeCap().String()) + println("Gas:", signedTx.Gas()) + println("To:", signedTx.To().Hex()) + println("Value:", signedTx.Value().String()) + println("Data:", hex.EncodeToString(signedTx.Data())) + println("AccessList:", signedTx.AccessList()) + println("BlobFeeCap:", signedTx.BlobGasFeeCap().String()) + println("BlobHashes:", signedTx.BlobHashes()) + if signedTx.BlobTxSidecar() != nil { + println("Sidecar contents:", signedTx.BlobTxSidecar()) + } + data, _ := signedTx.MarshalBinary() + + encodedData := hexutil.Encode(data) + var decodedTx types.Transaction + if errors.Is(err, decodedTx.DecodeRLP(rlp.NewStream(bytes.NewReader([]byte(encodedData)), 0))) { + println("ERROR DECODING RLP", err.Error()) + } + } p.logger.Info("Host issuing l1 tx", log.TxKey, signedTx.Hash(), "size", signedTx.Size()/1024, "retries", retries) + + //FIXME here rlp: expected input string or byte for *uint256.Int, decoding into (types.BlobTx).ChainID err = p.ethClient.SendTransaction(signedTx) if err != nil { - println("COULD NOT BROADCAST ChainId", signedTx.ChainId().Uint64(), err.Error()) + println("COULD NOT SendTransaction", signedTx.ChainId().Uint64(), err.Error()) return errors.Wrap(err, "could not broadcast L1 tx") } p.logger.Info("Successfully submitted tx to L1", "txHash", signedTx.Hash()) diff --git a/go/wallet/wallet.go b/go/wallet/wallet.go index 25d92b5413..1a97410a83 100644 --- a/go/wallet/wallet.go +++ b/go/wallet/wallet.go @@ -68,7 +68,7 @@ func NewInMemoryWalletFromConfig(pkStr string, l1ChainID int64, logger gethlog.L // SignTransaction returns a signed transaction func (m *inMemoryWallet) SignTransaction(tx types.TxData) (*types.Transaction, error) { - return types.SignNewTx(m.prvKey, types.NewCancunSigner(m.chainID), tx) + return types.MustSignNewTx(m.prvKey, types.NewCancunSigner(m.chainID), tx), nil } // Address returns the current wallet address diff --git a/integration/ethereummock/node.go b/integration/ethereummock/node.go index b9a29b6a2b..c09210b8a2 100644 --- a/integration/ethereummock/node.go +++ b/integration/ethereummock/node.go @@ -88,10 +88,6 @@ type Node struct { logger gethlog.Logger } -func (m *Node) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, _ int) (types.TxData, error) { - return m.PrepareTransactionToSend(ctx, txData, from) -} - func (m *Node) PrepareTransactionToSend(_ context.Context, txData types.TxData, _ gethcommon.Address) (types.TxData, error) { switch tx := txData.(type) { case *types.LegacyTx: @@ -103,6 +99,10 @@ func (m *Node) PrepareTransactionToSend(_ context.Context, txData types.TxData, } } +func (m *Node) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, _ uint64, _ int) (types.TxData, error) { + return m.PrepareTransactionToSend(ctx, txData, from) +} + func createLegacyTx(txData types.TxData) (types.TxData, error) { tx := types.NewTx(txData) return &types.LegacyTx{