mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Implement Horizontally Sharded Blob Mempool
This commit is contained in:
parent
35dd84ce29
commit
1d59ebae22
2 changed files with 40 additions and 1 deletions
|
|
@ -150,12 +150,15 @@ type ConsensusAPI struct {
|
||||||
|
|
||||||
forkchoiceLock sync.Mutex // Lock for the forkChoiceUpdated method
|
forkchoiceLock sync.Mutex // Lock for the forkChoiceUpdated method
|
||||||
newPayloadLock sync.Mutex // Lock for the NewPayload method
|
newPayloadLock sync.Mutex // Lock for the NewPayload method
|
||||||
|
|
||||||
|
isProposer atomic.Bool // Tracks if the node is currently identified as a proposer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConsensusAPI creates a new consensus api for the given backend.
|
// NewConsensusAPI creates a new consensus api for the given backend.
|
||||||
// The underlying blockchain needs to have a valid terminal total difficulty set.
|
// The underlying blockchain needs to have a valid terminal total difficulty set.
|
||||||
func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
|
func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
|
||||||
api := newConsensusAPIWithoutHeartbeat(eth)
|
api := newConsensusAPIWithoutHeartbeat(eth)
|
||||||
|
api.isProposer.Store(false)
|
||||||
go api.heartbeat()
|
go api.heartbeat()
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
@ -172,6 +175,7 @@ func newConsensusAPIWithoutHeartbeat(eth *eth.Ethereum) *ConsensusAPI {
|
||||||
invalidBlocksHits: make(map[common.Hash]int),
|
invalidBlocksHits: make(map[common.Hash]int),
|
||||||
invalidTipsets: make(map[common.Hash]*types.Header),
|
invalidTipsets: make(map[common.Hash]*types.Header),
|
||||||
}
|
}
|
||||||
|
api.isProposer.Store(false)
|
||||||
eth.Downloader().SetBadBlockCallback(api.setInvalidAncestor)
|
eth.Downloader().SetBadBlockCallback(api.setInvalidAncestor)
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
@ -198,6 +202,9 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, pa
|
||||||
case !api.checkFork(payloadAttributes.Timestamp, forks.Paris, forks.Shanghai):
|
case !api.checkFork(payloadAttributes.Timestamp, forks.Paris, forks.Shanghai):
|
||||||
return engine.STATUS_INVALID, paramsErr("fcuV1 called post-shanghai")
|
return engine.STATUS_INVALID, paramsErr("fcuV1 called post-shanghai")
|
||||||
}
|
}
|
||||||
|
api.isProposer.Store(true)
|
||||||
|
} else {
|
||||||
|
api.isProposer.Store(false)
|
||||||
}
|
}
|
||||||
return api.forkchoiceUpdated(update, payloadAttributes, engine.PayloadV1, false)
|
return api.forkchoiceUpdated(update, payloadAttributes, engine.PayloadV1, false)
|
||||||
}
|
}
|
||||||
|
|
@ -216,6 +223,9 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, pa
|
||||||
case !api.checkFork(params.Timestamp, forks.Paris, forks.Shanghai):
|
case !api.checkFork(params.Timestamp, forks.Paris, forks.Shanghai):
|
||||||
return engine.STATUS_INVALID, unsupportedForkErr("fcuV2 must only be called with paris or shanghai payloads")
|
return engine.STATUS_INVALID, unsupportedForkErr("fcuV2 must only be called with paris or shanghai payloads")
|
||||||
}
|
}
|
||||||
|
api.isProposer.Store(true)
|
||||||
|
} else {
|
||||||
|
api.isProposer.Store(false)
|
||||||
}
|
}
|
||||||
return api.forkchoiceUpdated(update, params, engine.PayloadV2, false)
|
return api.forkchoiceUpdated(update, params, engine.PayloadV2, false)
|
||||||
}
|
}
|
||||||
|
|
@ -232,6 +242,9 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
|
||||||
case !api.checkFork(params.Timestamp, forks.Cancun, forks.Prague):
|
case !api.checkFork(params.Timestamp, forks.Cancun, forks.Prague):
|
||||||
return engine.STATUS_INVALID, unsupportedForkErr("fcuV3 must only be called for cancun or prague payloads")
|
return engine.STATUS_INVALID, unsupportedForkErr("fcuV3 must only be called for cancun or prague payloads")
|
||||||
}
|
}
|
||||||
|
api.isProposer.Store(true)
|
||||||
|
} else {
|
||||||
|
api.isProposer.Store(false)
|
||||||
}
|
}
|
||||||
// TODO(matt): the spec requires that fcu is applied when called on a valid
|
// TODO(matt): the spec requires that fcu is applied when called on a valid
|
||||||
// hash, even if params are wrong. To do this we need to split up
|
// hash, even if params are wrong. To do this we need to split up
|
||||||
|
|
@ -240,6 +253,10 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
|
||||||
return api.forkchoiceUpdated(update, params, engine.PayloadV3, false)
|
return api.forkchoiceUpdated(update, params, engine.PayloadV3, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *ConsensusAPI) IsProposer() bool {
|
||||||
|
return api.isProposer.Load()
|
||||||
|
}
|
||||||
|
|
||||||
func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes, payloadVersion engine.PayloadVersion, payloadWitness bool) (engine.ForkChoiceResponse, error) {
|
func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes, payloadVersion engine.PayloadVersion, payloadWitness bool) (engine.ForkChoiceResponse, error) {
|
||||||
api.forkchoiceLock.Lock()
|
api.forkchoiceLock.Lock()
|
||||||
defer api.forkchoiceLock.Unlock()
|
defer api.forkchoiceLock.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -514,16 +514,38 @@ func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
if err := msg.Decode(&txs); err != nil {
|
if err := msg.Decode(&txs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
peerID := peer.ID()
|
||||||
|
peerIDLast4 := peerID[len(peerID)-1] & 0x0F
|
||||||
|
|
||||||
|
|
||||||
|
isProposer := false
|
||||||
|
var filteredTxs []*types.Transaction
|
||||||
|
|
||||||
for i, tx := range txs.PooledTransactionsResponse {
|
for i, tx := range txs.PooledTransactionsResponse {
|
||||||
// Validate and mark the remote transaction
|
// Validate and mark the remote transaction
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
|
return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
|
||||||
}
|
}
|
||||||
|
txHash := tx.Hash()
|
||||||
|
txHashLast4 := txHash[len(txHash)-1] & 0x0F
|
||||||
|
|
||||||
|
if txHashLast4 != peerIDLast4 && !isProposer && tx.Type() == types.BlobTxType {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
peer.markTransaction(tx.Hash())
|
peer.markTransaction(tx.Hash())
|
||||||
|
filteredTxs = append(filteredTxs, tx)
|
||||||
}
|
}
|
||||||
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
|
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
|
||||||
|
|
||||||
return backend.Handle(peer, &txs.PooledTransactionsResponse)
|
if len(filteredTxs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return backend.Handle(peer, &PooledTransactionsPacket{
|
||||||
|
PooledTransactionsResponse: filteredTxs,
|
||||||
|
RequestId: txs.RequestId,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
|
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue