dev: ensure consistency in BPS bundle result (#2479)
* dev: ensure consistency in BPS bundle result * fix: remove env operation once the sim is discarded & rename
This commit is contained in:
parent
c77bb1110d
commit
08769ead2b
@ -6,6 +6,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
@ -40,6 +42,12 @@ func (b *BidArgs) ToBid(builder common.Address, signer Signer) (*Bid, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(b.RawBid.UnRevertible) > len(txs) {
|
||||
return nil, fmt.Errorf("expect NonRevertible no more than %d", len(txs))
|
||||
}
|
||||
unRevertibleHashes := mapset.NewThreadUnsafeSetWithSize[common.Hash](len(b.RawBid.UnRevertible))
|
||||
unRevertibleHashes.Append(b.RawBid.UnRevertible...)
|
||||
|
||||
if len(b.PayBidTx) != 0 {
|
||||
var payBidTx = new(Transaction)
|
||||
err = payBidTx.UnmarshalBinary(b.PayBidTx)
|
||||
@ -51,14 +59,15 @@ func (b *BidArgs) ToBid(builder common.Address, signer Signer) (*Bid, error) {
|
||||
}
|
||||
|
||||
bid := &Bid{
|
||||
Builder: builder,
|
||||
BlockNumber: b.RawBid.BlockNumber,
|
||||
ParentHash: b.RawBid.ParentHash,
|
||||
Txs: txs,
|
||||
GasUsed: b.RawBid.GasUsed + b.PayBidTxGasUsed,
|
||||
GasFee: b.RawBid.GasFee,
|
||||
BuilderFee: b.RawBid.BuilderFee,
|
||||
rawBid: *b.RawBid,
|
||||
Builder: builder,
|
||||
BlockNumber: b.RawBid.BlockNumber,
|
||||
ParentHash: b.RawBid.ParentHash,
|
||||
Txs: txs,
|
||||
UnRevertible: unRevertibleHashes,
|
||||
GasUsed: b.RawBid.GasUsed + b.PayBidTxGasUsed,
|
||||
GasFee: b.RawBid.GasFee,
|
||||
BuilderFee: b.RawBid.BuilderFee,
|
||||
rawBid: *b.RawBid,
|
||||
}
|
||||
|
||||
if bid.BuilderFee == nil {
|
||||
@ -70,12 +79,13 @@ func (b *BidArgs) ToBid(builder common.Address, signer Signer) (*Bid, error) {
|
||||
|
||||
// RawBid represents a raw bid from builder directly.
|
||||
type RawBid struct {
|
||||
BlockNumber uint64 `json:"blockNumber"`
|
||||
ParentHash common.Hash `json:"parentHash"`
|
||||
Txs []hexutil.Bytes `json:"txs"`
|
||||
GasUsed uint64 `json:"gasUsed"`
|
||||
GasFee *big.Int `json:"gasFee"`
|
||||
BuilderFee *big.Int `json:"builderFee"`
|
||||
BlockNumber uint64 `json:"blockNumber"`
|
||||
ParentHash common.Hash `json:"parentHash"`
|
||||
Txs []hexutil.Bytes `json:"txs"`
|
||||
UnRevertible []common.Hash `json:"unRevertible"`
|
||||
GasUsed uint64 `json:"gasUsed"`
|
||||
GasFee *big.Int `json:"gasFee"`
|
||||
BuilderFee *big.Int `json:"builderFee"`
|
||||
|
||||
hash atomic.Value
|
||||
}
|
||||
@ -154,13 +164,14 @@ func (b *RawBid) Hash() common.Hash {
|
||||
|
||||
// Bid represents a bid.
|
||||
type Bid struct {
|
||||
Builder common.Address
|
||||
BlockNumber uint64
|
||||
ParentHash common.Hash
|
||||
Txs Transactions
|
||||
GasUsed uint64
|
||||
GasFee *big.Int
|
||||
BuilderFee *big.Int
|
||||
Builder common.Address
|
||||
BlockNumber uint64
|
||||
ParentHash common.Hash
|
||||
Txs Transactions
|
||||
UnRevertible mapset.Set[common.Hash]
|
||||
GasUsed uint64
|
||||
GasFee *big.Int
|
||||
BuilderFee *big.Int
|
||||
|
||||
rawBid RawBid
|
||||
}
|
||||
|
@ -613,7 +613,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
|
||||
break
|
||||
}
|
||||
|
||||
err = bidRuntime.commitTransaction(b.chain, b.chainConfig, tx)
|
||||
err = bidRuntime.commitTransaction(b.chain, b.chainConfig, tx, bidRuntime.bid.UnRevertible.Contains(tx.Hash()))
|
||||
if err != nil {
|
||||
log.Error("BidSimulator: failed to commit tx", "bidHash", bidRuntime.bid.Hash(), "tx", tx.Hash(), "err", err)
|
||||
err = fmt.Errorf("invalid tx in bid, %v", err)
|
||||
@ -668,7 +668,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
|
||||
|
||||
// commit payBidTx at the end of the block
|
||||
bidRuntime.env.gasPool.AddGas(params.PayBidTxGasLimit)
|
||||
err = bidRuntime.commitTransaction(b.chain, b.chainConfig, payBidTx)
|
||||
err = bidRuntime.commitTransaction(b.chain, b.chainConfig, payBidTx, true)
|
||||
if err != nil {
|
||||
log.Error("BidSimulator: failed to commit tx", "builder", bidRuntime.bid.Builder,
|
||||
"bidHash", bidRuntime.bid.Hash(), "tx", payBidTx.Hash(), "err", err)
|
||||
@ -749,12 +749,10 @@ func (r *BidRuntime) packReward(validatorCommission uint64) {
|
||||
r.packedValidatorReward.Sub(r.packedValidatorReward, r.bid.BuilderFee)
|
||||
}
|
||||
|
||||
func (r *BidRuntime) commitTransaction(chain *core.BlockChain, chainConfig *params.ChainConfig, tx *types.Transaction) error {
|
||||
func (r *BidRuntime) commitTransaction(chain *core.BlockChain, chainConfig *params.ChainConfig, tx *types.Transaction, unRevertible bool) error {
|
||||
var (
|
||||
env = r.env
|
||||
snap = env.state.Snapshot()
|
||||
gp = env.gasPool.Gas()
|
||||
sc *types.BlobSidecar
|
||||
env = r.env
|
||||
sc *types.BlobSidecar
|
||||
)
|
||||
|
||||
// Start executing the transaction
|
||||
@ -777,9 +775,9 @@ func (r *BidRuntime) commitTransaction(chain *core.BlockChain, chainConfig *para
|
||||
receipt, err := core.ApplyTransaction(chainConfig, chain, &env.coinbase, env.gasPool, env.state, env.header, tx,
|
||||
&env.header.GasUsed, *chain.GetVMConfig(), core.NewReceiptBloomGenerator())
|
||||
if err != nil {
|
||||
env.state.RevertToSnapshot(snap)
|
||||
env.gasPool.SetGas(gp)
|
||||
return err
|
||||
} else if unRevertible && receipt.Status == types.ReceiptStatusFailed {
|
||||
return errors.New("no revertible transaction failed")
|
||||
}
|
||||
|
||||
if tx.Type() == types.BlobTxType {
|
||||
|
Loading…
Reference in New Issue
Block a user