Skip to content

Commit

Permalink
Merge pull request #280 from forta-network/caner/forta-1332-tighten-j…
Browse files Browse the repository at this point in the history
…son-rpc-thresholds

Readjust chain thresholds to reduce allowed delay
  • Loading branch information
canercidam authored Nov 2, 2023
2 parents db93c15 + 1d29640 commit 7b74204
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 75 deletions.
2 changes: 1 addition & 1 deletion feeds/timeline/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestTimeline_CalculateLag(t *testing.T) {
r.Equal(float64(1+5+9+13+15+2)/float64(6), lag)
estimate, ok := blockTimeline.EstimateBlockScore()
r.True(ok)
r.Equal(0.625, estimate)
r.Equal(0.0625, estimate)

testDelay := time.Second
blockTimeline.delay = &testDelay
Expand Down
66 changes: 9 additions & 57 deletions protocol/settings/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type ChainSettings struct {
EnableTrace bool
JsonRpcRateLimiting *RateLimit
InspectionInterval int // in block number

DefaultOffset int
SafeOffset int
BlockThreshold int
BlockThreshold int
}

// RateLimit is token bucket algorithm parameters.
Expand All @@ -35,95 +32,58 @@ var allChainSettings = []ChainSettings{
EnableTrace: true,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 50,

DefaultOffset: 0,
SafeOffset: 1,
BlockThreshold: 20,
BlockThreshold: 8,
},
{
ChainID: 10,
Name: "Optimism",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 100,

DefaultOffset: 0,
SafeOffset: 5,
BlockThreshold: 100,
BlockThreshold: 8,
},
{
ChainID: 56,
Name: "BSC",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 250,

DefaultOffset: 0,
SafeOffset: 3,
BlockThreshold: 50,
BlockThreshold: 20,
},
{
ChainID: 137,
Name: "Polygon",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 70,

DefaultOffset: 0,
SafeOffset: 4,
BlockThreshold: 70,
BlockThreshold: 30,
},
{
ChainID: 250,
Name: "Fantom",
EnableTrace: true,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 750,

DefaultOffset: 0,
SafeOffset: 5,
BlockThreshold: 100,
BlockThreshold: 35,
},
{
ChainID: 42161,
Name: "Arbitrum",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 1500,

DefaultOffset: 0,
SafeOffset: 60,
BlockThreshold: 1200,
BlockThreshold: 80,
},
{
ChainID: 43114,
Name: "Avalanche",
EnableTrace: false,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 350,

DefaultOffset: 0,
SafeOffset: 4,
BlockThreshold: 70,
BlockThreshold: 30,
},
}

// ValidateChainSettings validates chain settings.
func ValidateChainSettings(chainID int) bool {
settings := GetChainSettings(chainID)
if settings.SafeOffset < 1 {
return false
}
if settings.BlockThreshold <= 0 {
return false
}
safeOffsetRate := float64(settings.SafeOffset) / float64(settings.BlockThreshold)
if safeOffsetRate < 0.05 || safeOffsetRate > 0.1 {
return false
}
return true
}

// GetChainSettings returns the settings for the chain.
func GetChainSettings(chainID int) *ChainSettings {
for _, settings := range allChainSettings {
Expand All @@ -136,14 +96,6 @@ func GetChainSettings(chainID int) *ChainSettings {
ChainID: chainID,
JsonRpcRateLimiting: defaultRateLimiting,
InspectionInterval: 50, // arbitrary value - not reliable

DefaultOffset: 0,
SafeOffset: 2,
BlockThreshold: 10,
BlockThreshold: 10,
}
}

// GetDefaultBlockOffset returns the block offset for a chain.
func GetBlockOffset(chainID int) int {
return GetChainSettings(chainID).DefaultOffset
}
17 changes: 0 additions & 17 deletions protocol/settings/chain_test.go

This file was deleted.

0 comments on commit 7b74204

Please sign in to comment.