From 38dc29b3e1f552a06047f27118f8452c540e378f Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Sun, 25 Feb 2024 23:16:19 +0100 Subject: [PATCH] eth/catalyst: implement getLocalTransaction, setLocalAccounts --- core/txpool/legacypool/legacypool.go | 5 +++++ core/txpool/txpool.go | 9 +++++++++ eth/catalyst/api.go | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 18ca27a11a..2e4cf64653 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1955,3 +1955,8 @@ func (t *lookup) RemotesBelowTip(threshold *big.Int) types.Transactions { func numSlots(tx *types.Transaction) int { return int((tx.Size() + txSlotSize - 1) / txSlotSize) } + +func (p *LegacyPool) AddLocalAddr(addr common.Address) { + p.locals.add(addr) + // TODO go through all txs to mark as local now +} diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 3d0d6bf617..b31a96320a 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/txpool/legacypool" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" @@ -465,6 +466,14 @@ func (p *TxPool) Status(hash common.Hash) TxStatus { return TxStatusUnknown } +func (p *TxPool) MarkLocal(addr common.Address) { + for _, pool := range p.subpools { + if sub, ok := pool.(*legacypool.LegacyPool); ok { + sub.AddLocalAddr(addr) + } + } +} + // Sync is a helper method for unit tests or simulator runs where the chain events // are arriving in quick succession, without any time in between them to run the // internal background reset operations. This method will run an explicit reset diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 44518612e8..8aaa0fdade 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -893,3 +893,25 @@ func getBody(block *types.Block) *engine.ExecutionPayloadBodyV1 { Withdrawals: withdrawals, } } + +func (c *ConsensusAPI) SetLocalAccounts(locals []common.Address) error { + for _, addr := range locals { + c.eth.TxPool().MarkLocal(addr) + } + return nil +} + +func (c *ConsensusAPI) GetLocalTransactions() ([][]byte, error) { + var res [][]byte + for _, addr := range c.eth.TxPool().Locals() { + pending, _ := c.eth.TxPool().ContentFrom(addr) + for _, tx := range pending { + m, err := tx.MarshalJSON() + if err != nil { + return [][]byte{}, nil + } + res = append(res, m) + } + } + return res, nil +}