reset listeners, doc typos
This commit is contained in:
parent
32be287887
commit
3cdac70a0d
@ -177,6 +177,10 @@ func (cp *ConsensusPoller) AddListener(listener OnConsensusBroken) {
|
|||||||
cp.listeners = append(cp.listeners, listener)
|
cp.listeners = append(cp.listeners, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cp *ConsensusPoller) ClearListeners() {
|
||||||
|
cp.listeners = []OnConsensusBroken{}
|
||||||
|
}
|
||||||
|
|
||||||
func WithBanPeriod(banPeriod time.Duration) ConsensusOpt {
|
func WithBanPeriod(banPeriod time.Duration) ConsensusOpt {
|
||||||
return func(cp *ConsensusPoller) {
|
return func(cp *ConsensusPoller) {
|
||||||
cp.banPeriod = banPeriod
|
cp.banPeriod = banPeriod
|
||||||
@ -524,7 +528,7 @@ func (cp *ConsensusPoller) Ban(be *Backend) {
|
|||||||
bs.finalizedBlockNumber = 0
|
bs.finalizedBlockNumber = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unban remove any bans from the backends
|
// Unban removes any bans from the backends
|
||||||
func (cp *ConsensusPoller) Unban(be *Backend) {
|
func (cp *ConsensusPoller) Unban(be *Backend) {
|
||||||
bs := cp.backendState[be]
|
bs := cp.backendState[be]
|
||||||
defer bs.backendStateMux.Unlock()
|
defer bs.backendStateMux.Unlock()
|
||||||
@ -532,14 +536,14 @@ func (cp *ConsensusPoller) Unban(be *Backend) {
|
|||||||
bs.bannedUntil = time.Now().Add(-10 * time.Hour)
|
bs.bannedUntil = time.Now().Add(-10 * time.Hour)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset remove any bans from the backends and reset their states
|
// Reset reset all backend states
|
||||||
func (cp *ConsensusPoller) Reset() {
|
func (cp *ConsensusPoller) Reset() {
|
||||||
for _, be := range cp.backendGroup.Backends {
|
for _, be := range cp.backendGroup.Backends {
|
||||||
cp.backendState[be] = &backendState{}
|
cp.backendState[be] = &backendState{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchBlock Convenient wrapper to make a request to get a block directly from the backend
|
// fetchBlock is a convenient wrapper to make a request to get a block directly from the backend
|
||||||
func (cp *ConsensusPoller) fetchBlock(ctx context.Context, be *Backend, block string) (blockNumber hexutil.Uint64, blockHash string, err error) {
|
func (cp *ConsensusPoller) fetchBlock(ctx context.Context, be *Backend, block string) (blockNumber hexutil.Uint64, blockHash string, err error) {
|
||||||
var rpcRes RPCRes
|
var rpcRes RPCRes
|
||||||
err = be.ForwardRPC(ctx, &rpcRes, "67", "eth_getBlockByNumber", block, false)
|
err = be.ForwardRPC(ctx, &rpcRes, "67", "eth_getBlockByNumber", block, false)
|
||||||
@ -557,7 +561,7 @@ func (cp *ConsensusPoller) fetchBlock(ctx context.Context, be *Backend, block st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPeerCount Convenient wrapper to retrieve the current peer count from the backend
|
// getPeerCount is a convenient wrapper to retrieve the current peer count from the backend
|
||||||
func (cp *ConsensusPoller) getPeerCount(ctx context.Context, be *Backend) (count uint64, err error) {
|
func (cp *ConsensusPoller) getPeerCount(ctx context.Context, be *Backend) (count uint64, err error) {
|
||||||
var rpcRes RPCRes
|
var rpcRes RPCRes
|
||||||
err = be.ForwardRPC(ctx, &rpcRes, "67", "net_peerCount")
|
err = be.ForwardRPC(ctx, &rpcRes, "67", "net_peerCount")
|
||||||
|
@ -80,6 +80,7 @@ func TestConsensus(t *testing.T) {
|
|||||||
node.handler.ResetOverrides()
|
node.handler.ResetOverrides()
|
||||||
node.mockBackend.Reset()
|
node.mockBackend.Reset()
|
||||||
}
|
}
|
||||||
|
bg.Consensus.ClearListeners()
|
||||||
bg.Consensus.Reset()
|
bg.Consensus.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user