Skip to content

Commit

Permalink
feat(taiko-client): proposer add blockAdddresses flags
Browse files Browse the repository at this point in the history
  • Loading branch information
luanxu-mxc committed Feb 3, 2025
1 parent 6920358 commit 1145cbc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/taiko-client/cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ var (
Category: proposerCategory,
EnvVars: []string{"TX_POOL_LOCALS_ONLY"},
}
TxPoolBlockAddresses = &cli.StringSliceFlag{
Name: "txPool.blockAddresses",
Usage: "Comma separated accounts to treat as locals (priority inclusion)",
Category: proposerCategory,
EnvVars: []string{"TX_POOL_BLOCK_ADDRESSES"},
}
MaxProposedTxListsPerEpoch = &cli.Uint64Flag{
Name: "txPool.maxTxListsPerEpoch",
Usage: "Maximum number of transaction lists which will be proposed inside one proposing epoch",
Expand Down Expand Up @@ -125,6 +131,7 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ProposeInterval,
TxPoolLocals,
TxPoolLocalsOnly,
TxPoolBlockAddresses,
ExtraData,
MinGasUsed,
MinTxListBytes,
Expand Down
11 changes: 11 additions & 0 deletions packages/taiko-client/proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
ExtraData string
ProposeInterval time.Duration
LocalAddresses []common.Address
blockAddresses []common.Address
LocalAddressesOnly bool
MinGasUsed uint64
MinTxListBytes uint64
Expand Down Expand Up @@ -68,6 +69,15 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
localAddresses = append(localAddresses, common.HexToAddress(account))
}
}
var blockAddresses []common.Address
if c.IsSet(flags.TxPoolBlockAddresses.Name) {
for _, account := range strings.Split(c.String(flags.TxPoolBlockAddresses.Name), ",") {
if trimmed := strings.TrimSpace(account); !common.IsHexAddress(trimmed) {
return nil, fmt.Errorf("invalid account in --txpool.blockAddresses: %s", trimmed)
}
blockAddresses = append(blockAddresses, common.HexToAddress(account))
}
}

minTip, err := utils.GWeiToWei(c.Float64(flags.MinTip.Name))
if err != nil {
Expand All @@ -94,6 +104,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
LocalAddressesOnly: c.Bool(flags.TxPoolLocalsOnly.Name),
MinGasUsed: c.Uint64(flags.MinGasUsed.Name),
MinTxListBytes: c.Uint64(flags.MinTxListBytes.Name),
blockAddresses: blockAddresses,
MinTip: minTip.Uint64(),
MinProposingInternal: c.Duration(flags.MinProposingInternal.Name),
MaxProposedTxListsPerEpoch: c.Uint64(flags.MaxProposedTxListsPerEpoch.Name),
Expand Down
27 changes: 27 additions & 0 deletions packages/taiko-client/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,33 @@ func (p *Proposer) fetchPoolContent(filterPoolContent bool) ([]types.Transaction
txLists = localTxsLists
}

if len(p.blockAddresses) > 0 {
var (
filteredTransactions []types.Transactions
signer = types.LatestSignerForChainID(p.rpc.L2.ChainID)
)
for _, txs := range txLists {
var filtered types.Transactions
for _, tx := range txs {
sender, err := types.Sender(signer, tx)
if err != nil {
return nil, err
}

for _, blockAddress := range p.blockAddresses {
if sender != blockAddress {
filtered = append(filtered, tx)
}
}
}

if filtered.Len() != 0 {
filteredTransactions = append(filteredTransactions, filtered)
}
}
txLists = filteredTransactions
}

log.Info("Transactions lists count", "count", len(txLists))

return txLists, nil
Expand Down

0 comments on commit 1145cbc

Please sign in to comment.