Skip to content

Commit

Permalink
Merge pull request #1266 from maticnetwork/master
Browse files Browse the repository at this point in the history
Back merge master to develop after v1.3.3 release
  • Loading branch information
pratikspatil024 authored Jun 12, 2024
2 parents e28c203 + 625774f commit d0a212b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 15 deletions.
13 changes: 9 additions & 4 deletions eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ const (
)

const (
maxUncleDist = 7 // Maximum allowed backward distance from the chain head
maxQueueDist = 32 // Maximum allowed distance from the chain head to queue
hashLimit = 256 // Maximum number of unique blocks or headers a peer may have announced
blockLimit = 64 // Maximum number of unique blocks a peer may have delivered
maxUncleDist = 7 // Maximum allowed backward distance from the chain head

// maxQueueDist is increased for bor to allow storing more block announcements
// near chain tip
maxQueueDist = 32 * 6 // Maximum allowed distance from the chain head to queue
hashLimit = 256 // Maximum number of unique blocks or headers a peer may have announced

// blockLimit is increased for bor to allow storing more unique blocks near chain tip
blockLimit = 64 * 3 // Maximum number of unique blocks a peer may have delivered
)

var (
Expand Down
4 changes: 2 additions & 2 deletions eth/gasprice/feehistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedL
return common.Big0, nil, nil, nil, fmt.Errorf("%w: %f", errInvalidPercentile, p)
}

if i > 0 && p < rewardPercentiles[i-1] {
return common.Big0, nil, nil, nil, fmt.Errorf("%w: #%d:%f > #%d:%f", errInvalidPercentile, i-1, rewardPercentiles[i-1], i, p)
if i > 0 && p <= rewardPercentiles[i-1] {
return common.Big0, nil, nil, nil, fmt.Errorf("%w: #%d:%f >= #%d:%f", errInvalidPercentile, i-1, rewardPercentiles[i-1], i, p)
}
}

Expand Down
21 changes: 19 additions & 2 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,30 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
log.Error("Propagating dangling block", "number", block.Number(), "hash", hash)
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
transfer := peers[:int(math.Sqrt(float64(len(peers))))]
for _, peer := range transfer {
peer.AsyncSendNewBlock(block, td)
}

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.Debug("Propagated block", "hash", hash, "recipients", len(transfer), "static and trusted recipients", len(staticAndTrustedPeers), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))

return
}
Expand All @@ -626,7 +643,7 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
peer.AsyncSendNewBlockHash(block)
}

log.Trace("Announced block", "hash", hash, "recipients", len(peers), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
log.Debug("Announced block", "hash", hash, "recipients", len(peers), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
}
}

Expand Down
10 changes: 10 additions & 0 deletions eth/protocols/eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
type knownCache struct {
hashes mapset.Set[common.Hash]
Expand Down
6 changes: 6 additions & 0 deletions ethstats/ethstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,12 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
}
}

// It's weird, but it's possible that the block is nil here.
// even though the check for error is done above.
if block == nil {
return nil
}

header = block.Header()
td = fullBackend.GetTd(context.Background(), header.Hash())

Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: bor
Version: 1.3.2
Version: 1.3.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.arm64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: bor
Version: 1.3.2
Version: 1.3.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.profile.amd64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: bor-profile
Version: 1.3.2
Version: 1.3.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.profile.arm64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: bor-profile
Version: 1.3.2
Version: 1.3.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.validator
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: bor-profile
Version: 1.3.2
Version: 1.3.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: bor-profile
Version: 1.3.2
Version: 1.3.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const (
VersionMajor = 1 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 2 // Patch version component of the current release
VersionPatch = 3 // Patch version component of the current release
VersionMeta = "" // Version metadata to append to the version string
)

Expand Down

0 comments on commit d0a212b

Please sign in to comment.