Skip to content

Commit

Permalink
feat: add config option to limit the about of blocks worth of logs to…
Browse files Browse the repository at this point in the history
… pull from Ethereum
  • Loading branch information
wwestgarth committed Jan 9, 2024
1 parent 13bd7df commit 7e86d51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
3 changes: 3 additions & 0 deletions core/evtforward/ethereum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ import (

const (
defaultDurationBetweenTwoRetry = 20 * time.Second
maxEthereumBlocks = 10000 // chosen because one of the validators wanted to use quicknode, and this is their limit
)

type Config struct {
// Level specifies the logging level of the Ethereum implementation of the
// Event Forwarder.
Level encoding.LogLevel `long:"log-level"`
MaxEthereumBlocks uint64 `long:"max-ethereum-blocks"`
PollEventRetryDuration encoding.Duration
}

func NewDefaultConfig() Config {
return Config{
Level: encoding.LogLevel{Level: logging.InfoLevel},
PollEventRetryDuration: encoding.Duration{Duration: defaultDurationBetweenTwoRetry},
MaxEthereumBlocks: maxEthereumBlocks,
}
}
40 changes: 22 additions & 18 deletions core/evtforward/ethereum/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
)

const (
engineLogger = "engine"
maxEthereumBlocks = 1000 // 3+ hour worth of blocks?
engineLogger = "engine"
)

//go:generate go run github.com/golang/mock/mockgen -destination mocks/forwarder_mock.go -package mocks code.vegaprotocol.io/vega/core/evtforward/ethereum Forwarder
Expand Down Expand Up @@ -136,11 +135,11 @@ func (e *Engine) Start() {
})
}

func issueFilteringRequest(from, to uint64) (ok bool, actualTo uint64) {
func issueFilteringRequest(from, to, nBlocks uint64) (ok bool, actualTo uint64) {
if from > to {
return false, 0
}
return true, min(from+maxEthereumBlocks, to)
return true, min(from+nBlocks, to)
}

func min(a, b uint64) uint64 {
Expand All @@ -151,38 +150,43 @@ func min(a, b uint64) uint64 {
}

func (e *Engine) gatherEvents(ctx context.Context) {
nBlocks := e.cfg.MaxEthereumBlocks
currentHeight := e.filterer.CurrentHeight(ctx)

// Ensure we are not issuing a filtering request for non-existing block.
if ok, nextHeight := issueFilteringRequest(e.nextCollateralBlockNumber, currentHeight); ok {
if ok, nextHeight := issueFilteringRequest(e.nextCollateralBlockNumber, currentHeight, nBlocks); ok {
e.filterer.FilterCollateralEvents(ctx, e.nextCollateralBlockNumber, nextHeight, func(event *commandspb.ChainEvent) {
e.forwarder.ForwardFromSelf(event)
})
e.nextCollateralBlockNumber = nextHeight + 1
}

// Ensure we are not issuing a filtering request for non-existing block.
if e.shouldFilterStakingBridge && e.nextStakingBlockNumber <= currentHeight {
e.filterer.FilterStakingEvents(ctx, e.nextStakingBlockNumber, currentHeight, func(event *commandspb.ChainEvent) {
e.forwarder.ForwardFromSelf(event)
})
e.nextStakingBlockNumber = currentHeight + 1
if e.shouldFilterStakingBridge {
if ok, nextHeight := issueFilteringRequest(e.nextStakingBlockNumber, currentHeight, nBlocks); ok {
e.filterer.FilterStakingEvents(ctx, e.nextStakingBlockNumber, nextHeight, func(event *commandspb.ChainEvent) {
e.forwarder.ForwardFromSelf(event)
})
e.nextStakingBlockNumber = nextHeight + 1
}
}

// Ensure we are not issuing a filtering request for non-existing block.
if e.shouldFilterVestingBridge && e.nextVestingBlockNumber <= currentHeight {
e.filterer.FilterVestingEvents(ctx, e.nextVestingBlockNumber, currentHeight, func(event *commandspb.ChainEvent) {
e.forwarder.ForwardFromSelf(event)
})
e.nextVestingBlockNumber = currentHeight + 1
if e.shouldFilterVestingBridge {
if ok, nextHeight := issueFilteringRequest(e.nextVestingBlockNumber, currentHeight, nBlocks); ok {
e.filterer.FilterVestingEvents(ctx, e.nextVestingBlockNumber, nextHeight, func(event *commandspb.ChainEvent) {
e.forwarder.ForwardFromSelf(event)
})
e.nextVestingBlockNumber = nextHeight + 1
}
}

// Ensure we are not issuing a filtering request for non-existing block.
if e.nextMultiSigControlBlockNumber <= currentHeight {
e.filterer.FilterMultisigControlEvents(ctx, e.nextMultiSigControlBlockNumber, currentHeight, func(event *commandspb.ChainEvent) {
if ok, nextHeight := issueFilteringRequest(e.nextMultiSigControlBlockNumber, currentHeight, nBlocks); ok {
e.filterer.FilterMultisigControlEvents(ctx, e.nextMultiSigControlBlockNumber, nextHeight, func(event *commandspb.ChainEvent) {
e.forwarder.ForwardFromSelf(event)
})
e.nextMultiSigControlBlockNumber = currentHeight + 1
e.nextMultiSigControlBlockNumber = nextHeight + 1
}
}

Expand Down

0 comments on commit 7e86d51

Please sign in to comment.