From 7942ab456d4ff9917a93a5363c9052294fa5e0f1 Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Wed, 6 Jul 2022 11:59:14 +0200 Subject: [PATCH] Add hooks to allow overriding Helper field in Syncer Needed by a Concordium fork of 'rosetta-cli' that understands account aliases. This is necessary for the 'rosetta-cli check:data' test to pass on a Concordium network. --- statefulsyncer/configuration.go | 8 ++++++++ statefulsyncer/stateful_syncer.go | 12 ++++++++---- syncer/configuration.go | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/statefulsyncer/configuration.go b/statefulsyncer/configuration.go index de1e37a04..0b7088372 100644 --- a/statefulsyncer/configuration.go +++ b/statefulsyncer/configuration.go @@ -16,6 +16,8 @@ package statefulsyncer import ( "time" + + "github.com/coinbase/rosetta-sdk-go/syncer" ) // Option is used to overwrite default values in @@ -66,3 +68,9 @@ func WithSeenConcurrency(concurrency int64) Option { s.seenSemaphoreSize = concurrency } } + +func WithExtraSyncerOpts(os ...syncer.Option) Option { + return func(s *StatefulSyncer) { + s.extraSyncerOpts = os + } +} diff --git a/statefulsyncer/stateful_syncer.go b/statefulsyncer/stateful_syncer.go index 9056645c7..c22bdc407 100644 --- a/statefulsyncer/stateful_syncer.go +++ b/statefulsyncer/stateful_syncer.go @@ -72,6 +72,8 @@ type StatefulSyncer struct { // BlockSeen occur concurrently. seenSemaphore *semaphore.Weighted seenSemaphoreSize int64 + + extraSyncerOpts []syncer.Option } // Logger is used by the statefulsyncer to @@ -162,10 +164,12 @@ func (s *StatefulSyncer) Sync(ctx context.Context, startIndex int64, endIndex in s, s, s.cancel, - syncer.WithPastBlocks(pastBlocks), - syncer.WithCacheSize(s.cacheSize), - syncer.WithMaxConcurrency(s.maxConcurrency), - syncer.WithAdjustmentWindow(s.adjustmentWindow), + append([]syncer.Option{ + syncer.WithPastBlocks(pastBlocks), + syncer.WithCacheSize(s.cacheSize), + syncer.WithMaxConcurrency(s.maxConcurrency), + syncer.WithAdjustmentWindow(s.adjustmentWindow), + }, s.extraSyncerOpts...)..., ) return syncer.Sync(ctx, startIndex, endIndex) diff --git a/syncer/configuration.go b/syncer/configuration.go index cd63664cc..7d4f24e80 100644 --- a/syncer/configuration.go +++ b/syncer/configuration.go @@ -65,3 +65,9 @@ func WithAdjustmentWindow(adjustmentWindow int64) Option { s.adjustmentWindow = adjustmentWindow } } + +func WithCustomHelper(h func(Helper) Helper) Option { + return func(s *Syncer) { + s.helper = h(s.helper) + } +}