Skip to content

Commit

Permalink
feat: set MaxBundleAliveBlock as bundle's default ddl
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Apr 25, 2024
1 parent 2d83277 commit 001f80b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 7 additions & 0 deletions core/types/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)

const (
// MaxBundleAliveBlock is the max alive block for bundle
MaxBundleAliveBlock = 100
// MaxBundleAliveTime is the max alive time for bundle
MaxBundleAliveTime = 5 * 60 // second
)

// SendBundleArgs represents the arguments for a call.
type SendBundleArgs struct {
Txs []hexutil.Bytes `json:"txs"`
Expand Down
24 changes: 10 additions & 14 deletions internal/ethapi/api_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)

const (
// MaxBundleAliveBlock is the max alive block for bundle
MaxBundleAliveBlock = 100
// MaxBundleAliveTime is the max alive time for bundle
MaxBundleAliveTime = 5 * 60 // second
MaxOracleBlocks = 21
DropBlocks = 3

InvalidBundleParamError = -38000
)
const InvalidBundleParamError = -38000

// PrivateTxBundleAPI offers an API for accepting bundled transactions
type PrivateTxBundleAPI struct {
Expand All @@ -44,11 +35,11 @@ func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBund
currentHeader := s.b.CurrentHeader()

if args.MaxBlockNumber == 0 && (args.MaxTimestamp == nil || *args.MaxTimestamp == 0) {
maxTimeStamp := currentHeader.Time + MaxBundleAliveTime
maxTimeStamp := currentHeader.Time + types.MaxBundleAliveTime
args.MaxTimestamp = &maxTimeStamp
}

if args.MaxBlockNumber != 0 && args.MaxBlockNumber > currentHeader.Number.Uint64()+MaxBundleAliveBlock {
if args.MaxBlockNumber != 0 && args.MaxBlockNumber > currentHeader.Number.Uint64()+types.MaxBundleAliveBlock {
return common.Hash{}, newBundleError(errors.New("the maxBlockNumber should not be lager than currentBlockNum + 100"))
}

Expand All @@ -62,8 +53,8 @@ func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBund
return common.Hash{}, newBundleError(errors.New("the maxTimestamp should not be less than currentBlockTimestamp"))
}

if (args.MaxTimestamp != nil && *args.MaxTimestamp > currentHeader.Time+MaxBundleAliveTime) ||
(args.MinTimestamp != nil && *args.MinTimestamp > currentHeader.Time+MaxBundleAliveTime) {
if (args.MaxTimestamp != nil && *args.MaxTimestamp > currentHeader.Time+types.MaxBundleAliveTime) ||
(args.MinTimestamp != nil && *args.MinTimestamp > currentHeader.Time+types.MaxBundleAliveTime) {
return common.Hash{}, newBundleError(errors.New("the minTimestamp/maxTimestamp should not be later than currentBlockTimestamp + 5 minutes"))
}

Expand Down Expand Up @@ -95,6 +86,11 @@ func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBund
RevertingTxHashes: args.RevertingTxHashes,
}

// If the maxBlockNumber and maxTimestamp are not set, set max ddl of bundle as types.MaxBundleAliveBlock
if bundle.MaxBlockNumber == 0 && bundle.MaxTimestamp == 0 {
bundle.MaxBlockNumber = currentHeader.Number.Uint64() + types.MaxBundleAliveBlock
}

err := s.b.SendBundle(ctx, bundle)
if err != nil {
return common.Hash{}, err
Expand Down

0 comments on commit 001f80b

Please sign in to comment.