Skip to content

Commit

Permalink
stashing
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Aug 19, 2024
1 parent 236afda commit f3bad53
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go/enclave/components/rollup_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (rc *rollupConsumerImpl) extractRollups(ctx context.Context, br *common.Blo

blobs, err := rc.blobResolver.FetchBlobs(ctx, br.Block.Header(), rollupHashes.BlobHashes)
if err != nil {
rc.logger.Crit("could not fetch blobs.", log.ErrKey, err)
rc.logger.Crit("could not fetch blobs consumer", log.ErrKey, err)
return nil
}
r, err := reconstructRollup(blobs)
Expand Down
32 changes: 30 additions & 2 deletions go/ethadapter/geth_rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
"math"
Expand Down Expand Up @@ -139,6 +140,35 @@ func (e *gethRPCClient) IsBlockAncestor(block *types.Block, maybeAncestor common
}

func (e *gethRPCClient) SendTransaction(signedTx *types.Transaction) error {
if signedTx.Type() == types.BlobTxType {
blobs := signedTx.BlobTxSidecar().Blobs
blobsPtrs := make([]*kzg4844.Blob, len(blobs))

for i := range blobs {
blobsPtrs[i] = &blobs[i]
}

rollup, _ := ReconstructRollup(blobsPtrs)
println("sending rollup blob: ", rollup.Hash().Hex())
}
ctx, cancel := context.WithTimeout(context.Background(), e.timeout)
defer cancel()

return e.client.SendTransaction(ctx, signedTx)
}

func (e *gethRPCClient) SendTransactionCtx(ctx context.Context, signedTx *types.Transaction) error {
if signedTx.Type() == types.BlobTxType {
blobs := signedTx.BlobTxSidecar().Blobs
blobsPtrs := make([]*kzg4844.Blob, len(blobs))

for i := range blobs {
blobsPtrs[i] = &blobs[i]
}

rollup, _ := ReconstructRollup(blobsPtrs)
println("sending rollup blob: ", rollup.Hash().Hex())
}
ctx, cancel := context.WithTimeout(context.Background(), e.timeout)
defer cancel()

Expand Down Expand Up @@ -360,9 +390,7 @@ func (e *gethRPCClient) prepareBlobTxToRetry(ctx context.Context, txData types.T
}
blobFeeCap := calcBlobFeeCap(blobBaseFee, retryNumber)

//chainId, _ := uint256.FromBig(big.NewInt(1337))
return &types.BlobTx{
//ChainID: chainId,
Nonce: nonce,
GasTipCap: uint256.MustFromBig(retryPrice), // aka maxPriorityFeePerGas
GasFeeCap: uint256.MustFromBig(retryPrice), // aka. maxFeePerGas
Expand Down
1 change: 1 addition & 0 deletions go/ethadapter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type EthClient interface {
BlockByHash(id gethcommon.Hash) (*types.Block, error) // retrieves a block given a hash
BlockByNumber(n *big.Int) (*types.Block, error) // retrieves a block given a number - returns head block if n is nil
SendTransaction(signedTx *types.Transaction) error // issues an ethereum transaction (expects signed tx)
SendTransactionCtx(ctx context.Context, signedTx *types.Transaction) error // issues an ethereum transaction (expects signed tx)
TransactionReceipt(hash gethcommon.Hash) (*types.Receipt, error) // fetches the ethereum transaction receipt
Nonce(address gethcommon.Address) (uint64, error) // fetches the account nonce to use in the next transaction
BalanceAt(account gethcommon.Address, blockNumber *big.Int) (*big.Int, error) // fetches the balance of the account
Expand Down
8 changes: 3 additions & 5 deletions go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ func (c *contractLibImpl) CreateBlobRollup(t *ethadapter.L1RollupTx) (types.TxDa
panic(err)
}

//serialized, err := rlp.EncodeToBytes(t.Rollup)
//if err != nil {
// return nil, fmt.Errorf("could not serialize rollup. Cause: %w", err)
//}

metaRollup := ManagementContract.StructsMetaRollup{
Hash: decodedRollup.Hash(),
Signature: decodedRollup.Header.Signature,
Expand Down Expand Up @@ -196,6 +191,9 @@ func (c *contractLibImpl) CreateBlobRollup(t *ethadapter.L1RollupTx) (types.TxDa
if sidecar, blobHashes, err = makeSidecar(blobs); err != nil {
return nil, fmt.Errorf("failed to make sidecar: %w", err)
}

println("creating rollup blob tx: ", decodedRollup.Hash().Hex())
println("creating rollup blob seq no: ", decodedRollup.Header.LastBatchSeqNo)
return &types.BlobTx{
To: *c.addr,
Data: data,
Expand Down
3 changes: 3 additions & 0 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ func (g *Guardian) periodicRollupProduction() {
g.logger.Error("Unable to create rollup", log.BatchSeqNoKey, fromBatch, log.ErrKey, err)
continue
}
println("PRODUCED ROLLUP: ", producedRollup.Hash().Hex())
println("PRODUCED timeExpired: ", timeExpired)
println("PRODUCED sizeExceeded: ", sizeExceeded)
// this method waits until the receipt is received
g.sl.L1Publisher().PublishRollup(producedRollup)
lastSuccessfulRollup = time.Now()
Expand Down
26 changes: 18 additions & 8 deletions go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (p *Publisher) ExtractObscuroRelevantTransactions(block *types.Block) ([]*e

blobs, err := p.blobResolver.FetchBlobs(p.sendingContext, block.Header(), rollupHashes.BlobHashes)
if err != nil {
p.logger.Crit("could not fetch blobs.", log.ErrKey, err)
p.logger.Crit("could not fetch blobs publisher", log.ErrKey, err)
return nil, nil, nil
}
encodedRlp, err := ethadapter.DecodeBlobs(blobs)
Expand Down Expand Up @@ -409,6 +409,10 @@ func (p *Publisher) ResyncImportantContracts() error {
// this method is guarded by a lock to ensure that only one transaction is attempted at a time to avoid nonce conflicts
// todo (@matt) this method should take a context so we can try to cancel if the tx is no longer required
func (p *Publisher) publishTransaction(tx types.TxData) error {
//FIXME config
timeout := 15 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// this log message seems superfluous but is useful to debug deadlock issues, we expect 'Host issuing l1 tx' soon
// after unless we're stuck blocking.
p.logger.Info("Host preparing to issue L1 tx")
Expand All @@ -420,6 +424,12 @@ func (p *Publisher) publishTransaction(tx types.TxData) error {

// while the publisher service is still alive we keep trying to get the transaction into the L1
for !p.hostStopper.IsStopping() {
// Check if the context has been canceled, and if so, exit early
if ctx.Err() != nil {
p.logger.Warn("Context canceled, aborting transaction publication")
return ctx.Err()
}

retries++ // count each attempt so we can increase gas price

// moved nonce fetching within this loop to ensure its up to date
Expand All @@ -430,7 +440,7 @@ func (p *Publisher) publishTransaction(tx types.TxData) error {
}

// update the tx gas price before each attempt
tx, err := p.ethClient.PrepareTransactionToRetry(p.sendingContext, tx, p.hostWallet.Address(), nonce, retries)
tx, err := p.ethClient.PrepareTransactionToRetry(ctx, tx, p.hostWallet.Address(), nonce, retries)
if err != nil {
return errors.Wrap(err, "could not estimate gas/gas price for L1 tx")
}
Expand All @@ -439,9 +449,9 @@ func (p *Publisher) publishTransaction(tx types.TxData) error {
if err != nil {
return errors.Wrap(err, "could not sign L1 tx")
}
p.logger.Info("Host issuing l1 tx", log.TxKey, signedTx.Hash(), "size", signedTx.Size()/1024, "retries", retries)
p.logger.Info("Host issuing L1 tx", log.TxKey, signedTx.Hash(), "size", signedTx.Size()/1024, "retries", retries)

err = p.ethClient.SendTransaction(signedTx)
err = p.ethClient.SendTransactionCtx(ctx, signedTx)
if err != nil {
// if there is a nonce gap, wait and retry after a short delay with exponential backoff
if strings.Contains(err.Error(), "nonce too low") {
Expand All @@ -454,11 +464,11 @@ func (p *Publisher) publishTransaction(tx types.TxData) error {
p.logger.Info("Successfully submitted tx to L1", "txHash", signedTx.Hash())

var receipt *types.Receipt
// retry until receipt is found
// retry until receipt is found or context is canceled
err = retry.Do(
func() error {
if p.hostStopper.IsStopping() {
return retry.FailFast(errors.New("host is stopping"))
if p.hostStopper.IsStopping() || ctx.Err() != nil {
return retry.FailFast(errors.New("host is stopping or context canceled"))
}
receipt, err = p.ethClient.TransactionReceipt(signedTx.Hash())
if err != nil {
Expand All @@ -473,7 +483,7 @@ func (p *Publisher) publishTransaction(tx types.TxData) error {
continue // try again with updated gas price
}

if err == nil && receipt.Status != types.ReceiptStatusSuccessful {
if receipt.Status != types.ReceiptStatusSuccessful {
return fmt.Errorf("unsuccessful receipt found for published L1 transaction, status=%d", receipt.Status)
}

Expand Down
6 changes: 6 additions & 0 deletions integration/ethereummock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func (m *Node) SendTransaction(tx *types.Transaction) error {
return nil
}

// FIXME implement ctx
func (m *Node) SendTransactionCtx(_ context.Context, tx *types.Transaction) error {
m.Network.BroadcastTx(tx)
return nil
}

func (m *Node) TransactionReceipt(_ gethcommon.Hash) (*types.Receipt, error) {
// all transactions are immediately processed
return &types.Receipt{
Expand Down
1 change: 1 addition & 0 deletions integration/simulation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func findRollupDups(list []*common.ExtRollup) map[common.L2BatchHash]int {
elementCount := make(map[common.L2BatchHash]int)

for _, item := range list {

Check failure on line 109 in integration/simulation/utils.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

// check if the item/element exist in the duplicate_frequency map
_, exist := elementCount[item.Hash()]
if exist {
Expand Down

0 comments on commit f3bad53

Please sign in to comment.