mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 14:03:46 +00:00
eth: broadcast block to static and trusted peers as well (#1258)
This commit is contained in:
parent
d8374ecf3c
commit
a0acefc04c
3 changed files with 31 additions and 1 deletions
|
|
@ -606,6 +606,17 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
|
||||||
log.Error("Propagating dangling block", "number", block.Number(), "hash", hash)
|
log.Error("Propagating dangling block", "number", block.Number(), "hash", hash)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are the static and trusted peers which are not
|
||||||
|
// in `transfer := peers[:int(math.Sqrt(float64(len(peers))))]`
|
||||||
|
staticAndTrustedPeers := []*ethPeer{}
|
||||||
|
|
||||||
|
for _, peer := range peers[int(math.Sqrt(float64(len(peers)))):] {
|
||||||
|
if peer.IsTrusted() || peer.IsStatic() {
|
||||||
|
staticAndTrustedPeers = append(staticAndTrustedPeers, peer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Send the block to a subset of our peers
|
// Send the block to a subset of our peers
|
||||||
transfer := peers[:int(math.Sqrt(float64(len(peers))))]
|
transfer := peers[:int(math.Sqrt(float64(len(peers))))]
|
||||||
for _, peer := range transfer {
|
for _, peer := range transfer {
|
||||||
|
|
@ -614,6 +625,14 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
|
||||||
|
|
||||||
log.Trace("Propagated block", "hash", hash, "recipients", len(transfer), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
|
log.Trace("Propagated block", "hash", hash, "recipients", len(transfer), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
|
||||||
|
|
||||||
|
// Send the block to the trusted and static peers
|
||||||
|
for _, peer := range staticAndTrustedPeers {
|
||||||
|
log.Trace("Propagating block to static and trusted peer", "hash", hash, "peerID", peer.ID())
|
||||||
|
peer.AsyncSendNewBlock(block, td)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Trace("Propagated same block to additional static and trusted peers", "hash", hash, "recipients", len(staticAndTrustedPeers), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Otherwise if the block is indeed in out own chain, announce it
|
// Otherwise if the block is indeed in out own chain, announce it
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,16 @@ func (p *Peer) RequestTxs(hashes []common.Hash) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsTrusted returns whether the peer is a trusted peer or not.
|
||||||
|
func (p *Peer) IsTrusted() bool {
|
||||||
|
return p.Info().Network.Trusted
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsStatic returns whether the peer is a static peer or not.
|
||||||
|
func (p *Peer) IsStatic() bool {
|
||||||
|
return p.Info().Network.Static
|
||||||
|
}
|
||||||
|
|
||||||
// knownCache is a cache for known hashes.
|
// knownCache is a cache for known hashes.
|
||||||
type knownCache struct {
|
type knownCache struct {
|
||||||
hashes mapset.Set[common.Hash]
|
hashes mapset.Set[common.Hash]
|
||||||
|
|
|
||||||
|
|
@ -2238,7 +2238,8 @@ func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.
|
||||||
func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int, borTx bool) map[string]interface{} {
|
func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int, borTx bool) map[string]interface{} {
|
||||||
from, _ := types.Sender(signer, tx)
|
from, _ := types.Sender(signer, tx)
|
||||||
|
|
||||||
txHash := common.Hash{}
|
var txHash common.Hash
|
||||||
|
|
||||||
if borTx {
|
if borTx {
|
||||||
txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(blockNumber, blockHash))
|
txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(blockNumber, blockHash))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue