Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

feat(proposer): add --txpool.localsOnly flag #326

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var (
Usage: "Comma separated accounts to treat as locals (priority inclusion)",
Category: proposerCategory,
}
TxPoolLocalsOnly = &cli.BoolFlag{
Name: "txpool.localsOnly",
Usage: "If set to true, proposer will only propose transactions of local accounts",
Value: false,
Category: proposerCategory,
}
ProposeEmptyBlocksInterval = &cli.StringFlag{
Name: "proposeEmptyBlockInterval",
Usage: "Time interval to propose empty blocks",
Expand Down Expand Up @@ -76,6 +82,7 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ProposeInterval,
CommitSlot,
TxPoolLocals,
TxPoolLocalsOnly,
ProposeEmptyBlocksInterval,
MinBlockGasLimit,
MaxProposedTxListsPerEpoch,
Expand Down
2 changes: 2 additions & 0 deletions proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
ProposeInterval *time.Duration
CommitSlot uint64
LocalAddresses []common.Address
LocalAddressesOnly bool
ProposeEmptyBlocksInterval *time.Duration
MinBlockGasLimit uint64
MaxProposedTxListsPerEpoch uint64
Expand Down Expand Up @@ -99,6 +100,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
ProposeInterval: proposingInterval,
CommitSlot: c.Uint64(flags.CommitSlot.Name),
LocalAddresses: localAddresses,
LocalAddressesOnly: c.Bool(flags.TxPoolLocalsOnly.Name),
ProposeEmptyBlocksInterval: proposeEmptyBlocksInterval,
MinBlockGasLimit: c.Uint64(flags.MinBlockGasLimit.Name),
MaxProposedTxListsPerEpoch: c.Uint64(flags.MaxProposedTxListsPerEpoch.Name),
Expand Down
29 changes: 29 additions & 0 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Proposer struct {
proposingTimer *time.Timer
commitSlot uint64
locals []common.Address
localsOnly bool
minBlockGasLimit *uint64
maxProposedTxListsPerEpoch uint64
proposeBlockTxGasLimit *uint64
Expand Down Expand Up @@ -86,6 +87,7 @@ func InitFromConfig(ctx context.Context, p *Proposer, cfg *Config) (err error) {
p.proposeBlockTxGasLimit = cfg.ProposeBlockTxGasLimit
p.wg = sync.WaitGroup{}
p.locals = cfg.LocalAddresses
p.localsOnly = cfg.LocalAddressesOnly
p.commitSlot = cfg.CommitSlot
p.maxProposedTxListsPerEpoch = cfg.MaxProposedTxListsPerEpoch
p.txReplacementTipMultiplier = cfg.ProposeBlockTxReplacementMultiplier
Expand Down Expand Up @@ -211,6 +213,33 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
return fmt.Errorf("failed to fetch transaction pool content: %w", err)
}

if p.localsOnly {
var (
localTxsLists []types.Transactions
signer = types.LatestSignerForChainID(p.rpc.L2ChainID)
)
for _, txs := range txLists {
var filtered types.Transactions
for _, tx := range txs {
sender, err := types.Sender(signer, tx)
if err != nil {
return err
}

for _, localAddress := range p.locals {
if sender == localAddress {
filtered = append(filtered, tx)
}
}
}

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

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

if len(txLists) == 0 {
Expand Down