Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tx to excluded list if it reverts
Browse files Browse the repository at this point in the history
bharath-123 committed Aug 13, 2024
1 parent 548f445 commit 32d7a3f
Showing 5 changed files with 1,889 additions and 16 deletions.
3 changes: 3 additions & 0 deletions core/error.go
Original file line number Diff line number Diff line change
@@ -107,4 +107,7 @@ var (

// ErrBlobTxCreate is returned if a blob transaction has no explicit to field.
ErrBlobTxCreate = errors.New("blob transaction of type create")

// ErrTxReverted is returned if a transaction is reverted.
ErrTxReverted = errors.New("transaction reverted")
)
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ module github.com/ethereum/go-ethereum
go 1.21

require (
buf.build/gen/go/astria/composer-apis/protocolbuffers/go v1.34.2-00000000000000-b8b0a7e37fa2.2
buf.build/gen/go/astria/composer-apis/protocolbuffers/go v1.34.2-00000000000000-bf2928746fde.2
buf.build/gen/go/astria/execution-apis/grpc/go v1.5.1-00000000000000-cdc3a35f6a0c.1
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.2-20240801092317-cdc3a35f6a0c.2
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.2-20240801092317-1af140bbf6af.2
buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.2-20240801092317-547455022126.2
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.2-20240807170122-b074164339d1.2
buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.2-20240807170122-24ff5bcd4581.2
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
github.com/Microsoft/go-winio v0.6.1
github.com/VictoriaMetrics/fastcache v1.12.1
@@ -86,6 +86,7 @@ require (
)

require (
buf.build/gen/go/astria/composer-apis/grpc/go v1.4.0-20240528191859-5569d2ee7204.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/DataDog/zstd v1.4.5 // indirect
1,830 changes: 1,830 additions & 0 deletions go.sum

Large diffs are not rendered by default.

57 changes: 44 additions & 13 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
@@ -236,11 +236,15 @@ func unbundleBuilderBundlePacket(
if builderBundlePacket == nil {
return types.Transactions{}, nil
}
if bytes.Compare(builderBundlePacket.GetBundle().GetParentHash(), parentHash) != 0 {

builderBundle := builderBundlePacket.GetBundle()
if bytes.Compare(builderBundle.GetParentHash(), parentHash) != 0 {
log.Error("parent hash does not match parent hash of the block", "parentHash", common.BytesToHash(parentHash).Hex(), "bundleParentHash", common.BytesToHash(builderBundlePacket.GetBundle().GetParentHash()).Hex())
return types.Transactions{}, nil
}

// TODO - bundle signature verification

ethTxs := types.Transactions{}
for _, tx := range builderBundlePacket.GetBundle().GetTransactions() {
ethTx, err := validateAndUnmarshalTx(height, tx, bridgeAddresses, bridgeAllowedAssets, bridgeSenderAddress)
@@ -257,7 +261,7 @@ func unbundleBuilderBundlePacket(
// ExecuteBlock drives deterministic derivation of a rollup block from sequencer
// block data
func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *astriaPb.ExecuteBlockRequest) (*astriaPb.ExecuteBlockResponse, error) {
log.Info("Trusted Buildoooor ExecuteBlock called", "prevBlockHash", common.BytesToHash(req.PrevBlockHash), "tx_count", len(req.Transactions), "timestamp", req.Timestamp)
log.Info("Trusted Builder ExecuteBlock called", "prevBlockHash", common.BytesToHash(req.PrevBlockHash), "tx_count", len(req.Transactions), "timestamp", req.Timestamp)
executeBlockRequestCount.Inc(1)
log.Info("Mode is set to", "simulateOnly", req.GetSimulateOnly())

@@ -281,7 +285,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
// the height that this block will be at
height := s.bc.CurrentBlock().Number.Uint64() + 1

log.Info("Calling extractBuilderBundleAndTxs")
log.Info("Extracting builder bundle and other txs")
builderBundlePacket, ethTxs, depositTxMapping, err := extractBuilderBundleAndTxs(req.Transactions, height, s.bridgeAddresses, s.bridgeAllowedAssets, s.bridgeSenderAddress)
if err != nil {
log.Error("failed to extract builder bundle and txs", "err", err)
@@ -294,17 +298,20 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
log.Info("No builder bundle packet found")
} else {
log.Info("Builder bundle packet found")
log.Info("Unbundling the builder bundle packet", "simulateOnly", req.GetSimulateOnly())
}

log.Info("Calling unbundleBuilderBundlePacket")
tobTxs, err := unbundleBuilderBundlePacket(builderBundlePacket, req.PrevBlockHash, height, s.bridgeAddresses, s.bridgeAllowedAssets, s.bridgeSenderAddress)
if err != nil {
log.Error("failed to unbundle builder bundle packet", "err", err)
return nil, status.Error(codes.InvalidArgument, "Could not unbundle builder bundle packet")
}
log.Info("Unbundle builder bundle packet completed", "tx_count", len(tobTxs))
if builderBundlePacket != nil {
log.Info("Unbundled the builder bundle packet", "tx_count", len(tobTxs))
}

txsToProcess := append(tobTxs, ethTxs...)
log.Info("Total txs to process", "tx_count", len(txsToProcess))

s.eth.TxPool().SetAstriaOrdered(txsToProcess)

@@ -315,33 +322,54 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
Random: common.Hash{},
FeeRecipient: s.nextFeeRecipient,
}
log.Info("Building payload")
payload, err := s.eth.Miner().BuildPayload(payloadAttributes)
if err != nil {
log.Error("failed to build payload", "err", err)
return nil, status.Error(codes.InvalidArgument, "Could not build block with provided txs")
}
log.Info("Built payload!")

// call blockchain.InsertChain to actually execute and write the blocks to
// state
log.Info("Extracting block out of payload!")
block, err := engine.ExecutableDataToBlock(*payload.Resolve().ExecutionPayload, nil, nil)
if err != nil {
log.Error("failed to convert executable data to block", err)
return nil, status.Error(codes.Internal, "failed to execute block")
}
log.Info("Extracted block out of payload!")

log.Info("Building included_transactions list by removing txs which are in the list of AstriaExcludedTxs")
excludedTransactions := s.eth.TxPool().AstriaExcludedFromBlock()
includedTransactions := make([]*sequencerblockv1alpha1.RollupData, 0, len(block.Transactions()))
for _, tx := range block.Transactions() {
if tx.Type() == types.DepositTxType {
depositTx, ok := depositTxMapping[tx.Hash().Hex()]
log.Info("excluded txs", "count", len(*excludedTransactions))
for _, blockTx := range block.Transactions() {
// ensure blockTx is not in excludedTxs
found := false
for _, tx := range *excludedTransactions {
if tx.Hash() == tx.Hash() {
found = true
log.Error("tx found in excluded txs", "blockTx hash", tx.Hash().Hex())
break
}
}
if found {
// ignore tx which has been excluded
continue
}

if blockTx.Type() == types.DepositTxType {
depositTx, ok := depositTxMapping[blockTx.Hash().Hex()]
if !ok {
log.Error("deposit tx not found in depositTxMapping", "tx hash", tx.Hash().Hex())
return nil, status.Error(codes.Internal, "deposit tx not found in depositTxMapping")
log.Error("deposit blockTx not found in depositTxMapping", "blockTx hash", blockTx.Hash().Hex())
return nil, status.Error(codes.Internal, "deposit blockTx not found in depositTxMapping")
}

includedTransactions = append(includedTransactions, &sequencerblockv1alpha1.RollupData{Value: &sequencerblockv1alpha1.RollupData_Deposit{Deposit: depositTx}})

} else {
marshalledTx, err := tx.MarshalBinary()
marshalledTx, err := blockTx.MarshalBinary()
if err != nil {
log.Error("failed to marshal transaction", "err", err)
return nil, status.Error(codes.Internal, "failed to marshal transaction")
@@ -351,15 +379,18 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
})
}
}
log.Info("included transactions", "count", len(includedTransactions))
log.Info("Built included tx list", "count", len(includedTransactions))

// we do not insert the block to the chain if we just want to simulate the transactions
if !req.GetSimulateOnly() {
log.Info("Inserting block to chain")
err = s.bc.InsertBlockWithoutSetHead(block)
if err != nil {
log.Error("failed to insert block to chain", "hash", block.Hash(), "prevHash", req.PrevBlockHash, "err", err)
return nil, status.Error(codes.Internal, "failed to insert block to chain")
}
} else {
log.Info("Skipping inserting block to chain as simulateOnly is set")
}

// remove txs from original mempool
@@ -383,7 +414,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
IncludedTransactions: includedTransactions,
}

log.Info("Trusted Buildoooor ExecuteBlock completed", "block_num", res.GetBlock().Number, "timestamp", res.GetBlock().Timestamp)
log.Info("Trusted Builder ExecuteBlock completed", "block_num", res.GetBlock().Number, "timestamp", res.GetBlock().Timestamp)
totalExecutedTxCount.Inc(int64(len(block.Transactions())))
executeBlockSuccessCount.Inc(1)
return res, nil
8 changes: 8 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
@@ -194,6 +194,10 @@ func (miner *Miner) commitTransaction(env *environment, tx *types.Transaction) e
if err != nil {
return err
}
if receipt.Status == types.ReceiptStatusFailed {
//log.Error("Transaction failed", "hash", tx.Hash())
return core.ErrTxReverted
}
env.txs = append(env.txs, tx)
env.receipts = append(env.receipts, receipt)
env.tcount++
@@ -286,12 +290,16 @@ func (miner *Miner) commitAstriaTransactions(env *environment, txs *types.Transa
case errors.Is(err, core.ErrNonceTooLow):
// New head notification data race between the transaction pool and miner, shift
log.Trace("Skipping transaction with low nonce", "sender", from, "nonce", tx.Nonce())
case errors.Is(err, core.ErrTxReverted):
// Transaction failed, discard the transaction and get the next in line
log.Trace("Transaction reverted", "hash", tx.Hash(), "err", err)
default:
// Strange error, discard the transaction and get the next in line (note, the
// nonce-too-high clause will prevent us from executing in vain).
log.Debug("Transaction failed, account skipped", "hash", tx.Hash(), "err", err)
}
if err != nil {
log.Error("Removing invalid transaction", "hash", tx.Hash(), "from", from, "err", err)
log.Trace("Marking transaction as invalid", "hash", tx.Hash(), "err", err)
miner.txpool.AddToAstriaExcludedFromBlock(tx)
}

0 comments on commit 32d7a3f

Please sign in to comment.