Skip to content

Commit

Permalink
stashing
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Jun 4, 2024
1 parent 33c5c55 commit ee39410
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
7 changes: 3 additions & 4 deletions go/ethadapter/geth_rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 26 additions & 11 deletions go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &ethadapter.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 &ethadapter.L1RollupTx{
Rollup: encodedRollup,
Rollup: rollup,
}

case RespondSecretMethod:
Expand Down
37 changes: 33 additions & 4 deletions go/host/l1/publisher.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion go/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions integration/ethereummock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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{
Expand Down

0 comments on commit ee39410

Please sign in to comment.