Commit 4c53cd9d authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #5793 from ethereum-optimism/aj/add-gaters

op-node: Enable temp ban connection gater
parents 2de63457 565a4e67
......@@ -163,9 +163,7 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter, metrics Host
if err != nil {
return nil, fmt.Errorf("failed to open connection gater: %w", err)
}
// TODO(CLI-4015): apply connGtr enhancements
// connGtr = gating.AddBanExpiry(connGtr, ps, log, cl, reporter)
//connGtr = gating.AddScoring(connGtr, ps, 0)
connGtr = gating.AddBanExpiry(connGtr, ps, log, clock.SystemClock, metrics)
connGtr = gating.AddMetering(connGtr, metrics)
connMngr, err := DefaultConnManager(conf)
......
......@@ -206,11 +206,7 @@ func (n *NodeP2P) Peers() []peer.ID {
}
func (n *NodeP2P) GetPeerScore(id peer.ID) (float64, error) {
scores, err := n.store.GetPeerScores(id)
if err != nil {
return 0, err
}
return scores.Gossip.Total, nil
return n.store.GetPeerScore(id)
}
func (n *NodeP2P) IsStatic(id peer.ID) bool {
......
......@@ -37,6 +37,9 @@ type ScoreDatastore interface {
// GetPeerScores returns the current scores for the specified peer
GetPeerScores(id peer.ID) (PeerScores, error)
// GetPeerScore returns the current combined score for the specified peer
GetPeerScore(id peer.ID) (float64, error)
// SetScore applies the given store diff to the specified peer
SetScore(id peer.ID, diff ScoreDiff) error
}
......
......@@ -78,6 +78,14 @@ func (d *scoreBook) GetPeerScores(id peer.ID) (PeerScores, error) {
return record.PeerScores, nil
}
func (d *scoreBook) GetPeerScore(id peer.ID) (float64, error) {
scores, err := d.GetPeerScores(id)
if err != nil {
return 0, err
}
return scores.Gossip.Total, nil
}
func (d *scoreBook) SetScore(id peer.ID, diff ScoreDiff) error {
return d.book.SetRecord(id, diff)
}
......
......@@ -188,6 +188,10 @@ func assertPeerScores(t *testing.T, store ExtendedPeerstore, id peer.ID, expecte
result, err := store.GetPeerScores(id)
require.NoError(t, err)
require.Equal(t, result, expected)
score, err := store.GetPeerScore(id)
require.NoError(t, err)
require.Equal(t, expected.Gossip.Total, score)
}
func createMemoryStore(t *testing.T) ExtendedPeerstore {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment