From 0ae117024d327dc5db05e62b672c48517557d3cb Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 13:28:05 -0700 Subject: [PATCH 01/15] Resolve merge conflict --- cmd/check_data.go | 4 +++ configuration/configuration.go | 9 ++++++ go.sum | 2 -- internal/statefulsyncer/stateful_syncer.go | 35 ++++++++++++++++++++++ internal/tester/data.go | 13 ++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/cmd/check_data.go b/cmd/check_data.go index 3a45d82a..b27eb0dc 100644 --- a/cmd/check_data.go +++ b/cmd/check_data.go @@ -137,6 +137,10 @@ func runCheckDataCmd(cmd *cobra.Command, args []string) { return dataTester.StartSyncing(ctx, StartIndex, EndIndex) }) + g.Go(func() error { + return dataTester.WatchEndCondition(ctx, Config) + }) + sigListeners := []context.CancelFunc{cancel} go handleSignals(sigListeners) diff --git a/configuration/configuration.go b/configuration/configuration.go index 3b0fb84a..26c079af 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -244,6 +244,12 @@ func DefaultConfiguration() *Configuration { } } +// EndCondition contains all condtions that check:data could end +type EndCondition struct { + // End once the node has reached tip + EndAtTip bool `json:"end_at_tip"` +} + // DataConfiguration contains all configurations to run check:data. type DataConfiguration struct { // ActiveReconciliationConcurrency is the concurrency to use while fetching accounts @@ -311,6 +317,9 @@ type DataConfiguration struct { // useful to just try to fetch all blocks before checking for balance // consistency. BalanceTrackingDisabled bool `json:"balance_tracking_disabled"` + + // EndCondition defines the condition when the Data API would end + EndCondition EndCondition `json:"end_condition"` } // Configuration contains all configuration settings for running diff --git a/go.sum b/go.sum index 2b151ab3..4c800806 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,6 @@ github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U= -github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200806182127-a0b262f73fc3 h1:GSHZTufGuZ8nhS1pPQRSezrNu9s5vegqntoVsRX2Q3w= -github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200806182127-a0b262f73fc3/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ= github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200807162047-31075a509b1f h1:U69ZwbTR10diY1MDi9LP/RxetVJzjd4bvIDUEs8XYvk= github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200807162047-31075a509b1f/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index 0a6a9d0c..e2740143 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -17,7 +17,9 @@ package statefulsyncer import ( "context" "fmt" + "log" "math/big" + "time" "github.com/coinbase/rosetta-cli/internal/logger" "github.com/coinbase/rosetta-cli/internal/storage" @@ -179,3 +181,36 @@ func (s *StatefulSyncer) Block( ) (*types.Block, error) { return s.fetcher.BlockRetry(ctx, network, block) } + +func (s *StatefulSyncer) EndAtTipLoop( + ctx context.Context, + tipDelay int64, + interval time.Duration, +) { + + tc := time.NewTicker(interval) + defer tc.Stop() + + for { + select { + case <-ctx.Done(): + return + + case <-tc.C: + atTip, err := s.blockStorage.AtTip(ctx, tipDelay) + if err != nil { + log.Printf( + "%s: unable to evaluate if at tip\n", + err.Error(), + ) + + continue + } + + if atTip { + s.cancel() + return + } + } + } +} diff --git a/internal/tester/data.go b/internal/tester/data.go index ef85e1e1..8f65ebdd 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -293,6 +293,19 @@ func (t *DataTester) StartPeriodicLogger( return ctx.Err() } +// WatchEndCondition starts go routines to watch the end conditions +func (t *DataTester) WatchEndCondition( + ctx context.Context, + config *configuration.Configuration, +) error { + if config.Data.EndCondition.EndAtTip { + // runs a go routine to end when reach tip + go t.syncer.EndAtTipLoop(ctx, config.TipDelay, 10*time.Second) + } + + return nil +} + // HandleErr is called when `check:data` returns an error. // If historical balance lookups are enabled, HandleErr will attempt to // automatically find any missing balance-changing operations. From 01986c8913fa8a8148c2444829c69b6e1578d145 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 13:29:34 -0700 Subject: [PATCH 02/15] Resolve merge conflict --- configuration/configuration.go | 14 +++++------ internal/statefulsyncer/stateful_syncer.go | 29 ++++++++++++++++++++-- internal/tester/data.go | 7 +++++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 26c079af..ff87c361 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -244,12 +244,6 @@ func DefaultConfiguration() *Configuration { } } -// EndCondition contains all condtions that check:data could end -type EndCondition struct { - // End once the node has reached tip - EndAtTip bool `json:"end_at_tip"` -} - // DataConfiguration contains all configurations to run check:data. type DataConfiguration struct { // ActiveReconciliationConcurrency is the concurrency to use while fetching accounts @@ -318,8 +312,12 @@ type DataConfiguration struct { // consistency. BalanceTrackingDisabled bool `json:"balance_tracking_disabled"` - // EndCondition defines the condition when the Data API would end - EndCondition EndCondition `json:"end_condition"` + // EndAtTip is an end condition. syncing will stop once the node has reached tip, + EndAtTip bool `json:"end_at_tip"` + + // EndSeconds is an end condtion that dictates how long the + // check:data command would be running for + EndSeconds int64 `json:"end_seconds"` } // Configuration contains all configuration settings for running diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index e2740143..248d246e 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -182,6 +182,7 @@ func (s *StatefulSyncer) Block( return s.fetcher.BlockRetry(ctx, network, block) } +// EndAtTipLoop runs a loop that evaluates end condition EndAtTip func (s *StatefulSyncer) EndAtTipLoop( ctx context.Context, tipDelay int64, @@ -200,17 +201,41 @@ func (s *StatefulSyncer) EndAtTipLoop( atTip, err := s.blockStorage.AtTip(ctx, tipDelay) if err != nil { log.Printf( - "%s: unable to evaluate if at tip\n", + "%s: unable to evaluate if node is at tip\n", err.Error(), ) - continue } if atTip { + log.Println("Node has reached tip") s.cancel() return } } } } + +// EndSecondsLoop runs a loop that evaluates end condition EndSeconds +func (s *StatefulSyncer) EndSecondsLoop( + ctx context.Context, + duration time.Duration, +) { + t := time.NewTimer(duration) + defer t.Stop() + + for { + select { + case <-ctx.Done(): + return + + case <-t.C: + log.Printf( + "StatefulSyncer has reached end condtion after %d seconds\n", + int(duration.Seconds()), + ) + s.cancel() + return + } + } +} diff --git a/internal/tester/data.go b/internal/tester/data.go index 8f65ebdd..18aae6a0 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -298,11 +298,16 @@ func (t *DataTester) WatchEndCondition( ctx context.Context, config *configuration.Configuration, ) error { - if config.Data.EndCondition.EndAtTip { + if config.Data.EndAtTip { // runs a go routine to end when reach tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay, 10*time.Second) } + if config.Data.EndSeconds != 0 { + // runs a go routine to end after X second + go t.syncer.EndSecondsLoop(ctx, time.Duration(config.Data.EndSeconds)*time.Second) + } + return nil } From 6e5eab1606d10dc99a6c37e34a3e8798203c7c6a Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 04:38:56 -0700 Subject: [PATCH 03/15] Use uint64 for EndSeconds condition --- configuration/configuration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index ff87c361..24e4605c 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -317,7 +317,7 @@ type DataConfiguration struct { // EndSeconds is an end condtion that dictates how long the // check:data command would be running for - EndSeconds int64 `json:"end_seconds"` + EndSeconds uint64 `json:"end_seconds"` } // Configuration contains all configuration settings for running From ec7991620d76f2adfae9c9daf6f7d20f685a2a06 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 04:57:28 -0700 Subject: [PATCH 04/15] Rename EndSeconds to EndDuration --- configuration/configuration.go | 4 ++-- internal/statefulsyncer/stateful_syncer.go | 8 ++++---- internal/tester/data.go | 15 +++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 24e4605c..a184d00b 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -315,9 +315,9 @@ type DataConfiguration struct { // EndAtTip is an end condition. syncing will stop once the node has reached tip, EndAtTip bool `json:"end_at_tip"` - // EndSeconds is an end condtion that dictates how long the + // EndDuration is an end condtion that dictates how long the // check:data command would be running for - EndSeconds uint64 `json:"end_seconds"` + EndDuration string `json:"end_duration"` } // Configuration contains all configuration settings for running diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index 248d246e..61f03552 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -201,7 +201,7 @@ func (s *StatefulSyncer) EndAtTipLoop( atTip, err := s.blockStorage.AtTip(ctx, tipDelay) if err != nil { log.Printf( - "%s: unable to evaluate if node is at tip\n", + "%s: unable to evaluate if node is at tip", err.Error(), ) continue @@ -216,8 +216,8 @@ func (s *StatefulSyncer) EndAtTipLoop( } } -// EndSecondsLoop runs a loop that evaluates end condition EndSeconds -func (s *StatefulSyncer) EndSecondsLoop( +// EndDurationLoop runs a loop that evaluates end condition EndDuration +func (s *StatefulSyncer) EndDurationLoop( ctx context.Context, duration time.Duration, ) { @@ -231,7 +231,7 @@ func (s *StatefulSyncer) EndSecondsLoop( case <-t.C: log.Printf( - "StatefulSyncer has reached end condtion after %d seconds\n", + "StatefulSyncer has reached end condtion after %d seconds", int(duration.Seconds()), ) s.cancel() diff --git a/internal/tester/data.go b/internal/tester/data.go index 18aae6a0..01d5072c 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -299,13 +299,20 @@ func (t *DataTester) WatchEndCondition( config *configuration.Configuration, ) error { if config.Data.EndAtTip { - // runs a go routine to end when reach tip + // runs a go routine that ends when reach tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay, 10*time.Second) } - if config.Data.EndSeconds != 0 { - // runs a go routine to end after X second - go t.syncer.EndSecondsLoop(ctx, time.Duration(config.Data.EndSeconds)*time.Second) + if config.Data.EndDuration != "" { + dur, err := time.ParseDuration(config.Data.EndDuration) + if err != nil { + log.Fatalf( + "%s: invalid during string for EndDuration", + err.Error(), + ) + } + // runs a go routine that ends after a duration + go t.syncer.EndDurationLoop(ctx, dur) } return nil From b275c5e7f7fd95f1334c4d20f1e39bcca52d611e Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 05:04:14 -0700 Subject: [PATCH 05/15] Fix lint --- internal/statefulsyncer/stateful_syncer.go | 1 - internal/tester/data.go | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index 61f03552..6ed1bbe1 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -188,7 +188,6 @@ func (s *StatefulSyncer) EndAtTipLoop( tipDelay int64, interval time.Duration, ) { - tc := time.NewTicker(interval) defer tc.Stop() diff --git a/internal/tester/data.go b/internal/tester/data.go index 01d5072c..f32832fb 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -54,6 +54,12 @@ const ( // // TODO: make configurable PeriodicLoggingFrequency = 10 * time.Second + + // EndAtTipCheckInterval is the frequency that EndAtTip condition + // is evaludated + // + // TODO: make configurable + EndAtTipCheckInterval = 10 * time.Second ) // DataTester coordinates the `check:data` test. @@ -300,7 +306,7 @@ func (t *DataTester) WatchEndCondition( ) error { if config.Data.EndAtTip { // runs a go routine that ends when reach tip - go t.syncer.EndAtTipLoop(ctx, config.TipDelay, 10*time.Second) + go t.syncer.EndAtTipLoop(ctx, config.TipDelay, EndAtTipCheckInterval) } if config.Data.EndDuration != "" { From 2e37ca13936ee8ec86c9fa429614e84d491a63ae Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 05:15:48 -0700 Subject: [PATCH 06/15] nit --- configuration/configuration.go | 2 +- internal/tester/data.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index a184d00b..d22f63d9 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -312,7 +312,7 @@ type DataConfiguration struct { // consistency. BalanceTrackingDisabled bool `json:"balance_tracking_disabled"` - // EndAtTip is an end condition. syncing will stop once the node has reached tip, + // EndAtTip is an end condition. syncing will stop once tip is reached EndAtTip bool `json:"end_at_tip"` // EndDuration is an end condtion that dictates how long the diff --git a/internal/tester/data.go b/internal/tester/data.go index f32832fb..ed9409e7 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -305,7 +305,7 @@ func (t *DataTester) WatchEndCondition( config *configuration.Configuration, ) error { if config.Data.EndAtTip { - // runs a go routine that ends when reach tip + // runs a go routine that ends when reaching tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay, EndAtTipCheckInterval) } From 18008b70f684ee86e91f2f19ca39bd92b6061d35 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 11:59:00 -0700 Subject: [PATCH 07/15] Resolve nits --- cmd/check_data.go | 2 +- internal/statefulsyncer/stateful_syncer.go | 6 +++--- internal/tester/data.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/check_data.go b/cmd/check_data.go index b27eb0dc..c2359e68 100644 --- a/cmd/check_data.go +++ b/cmd/check_data.go @@ -138,7 +138,7 @@ func runCheckDataCmd(cmd *cobra.Command, args []string) { }) g.Go(func() error { - return dataTester.WatchEndCondition(ctx, Config) + return dataTester.WatchEndConditions(ctx, Config) }) sigListeners := []context.CancelFunc{cancel} diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index 6ed1bbe1..2cf8ddc2 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -200,14 +200,14 @@ func (s *StatefulSyncer) EndAtTipLoop( atTip, err := s.blockStorage.AtTip(ctx, tipDelay) if err != nil { log.Printf( - "%s: unable to evaluate if node is at tip", + "%s: unable to evaluate if syncer is at tip", err.Error(), ) continue } if atTip { - log.Println("Node has reached tip") + log.Println("syncer has reached tip") s.cancel() return } @@ -230,7 +230,7 @@ func (s *StatefulSyncer) EndDurationLoop( case <-t.C: log.Printf( - "StatefulSyncer has reached end condtion after %d seconds", + "syncer has reached end condtion after %d seconds", int(duration.Seconds()), ) s.cancel() diff --git a/internal/tester/data.go b/internal/tester/data.go index ed9409e7..b5c241d8 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -300,7 +300,7 @@ func (t *DataTester) StartPeriodicLogger( } // WatchEndCondition starts go routines to watch the end conditions -func (t *DataTester) WatchEndCondition( +func (t *DataTester) WatchEndConditions( ctx context.Context, config *configuration.Configuration, ) error { From 544b04a1cfb3db7917c450e139f519bffb7ffafa Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 12:07:45 -0700 Subject: [PATCH 08/15] Move end condtions into a nested struct --- configuration/configuration.go | 18 ++++++++++++------ internal/tester/data.go | 8 ++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index d22f63d9..79ed7464 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -244,6 +244,16 @@ func DefaultConfiguration() *Configuration { } } +// EndCondition contains all the conditions for the syncer to stop. +type EndCondition struct { + // EndAtTip determines if syncer should stop once it reached the tip + EndAtTip bool `json:"end_at_tip"` + + // EndDuration is an end condtion that dictates how long the + // check:data command would be running for + EndDuration string `json:"end_duration"` +} + // DataConfiguration contains all configurations to run check:data. type DataConfiguration struct { // ActiveReconciliationConcurrency is the concurrency to use while fetching accounts @@ -312,12 +322,8 @@ type DataConfiguration struct { // consistency. BalanceTrackingDisabled bool `json:"balance_tracking_disabled"` - // EndAtTip is an end condition. syncing will stop once tip is reached - EndAtTip bool `json:"end_at_tip"` - - // EndDuration is an end condtion that dictates how long the - // check:data command would be running for - EndDuration string `json:"end_duration"` + // EndCondition contains the conditions for the syncer to stop + EndCondition EndCondition `json:"end_condition"` } // Configuration contains all configuration settings for running diff --git a/internal/tester/data.go b/internal/tester/data.go index b5c241d8..7d831491 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -299,18 +299,18 @@ func (t *DataTester) StartPeriodicLogger( return ctx.Err() } -// WatchEndCondition starts go routines to watch the end conditions +// WatchEndConditions starts go routines to watch the end conditions func (t *DataTester) WatchEndConditions( ctx context.Context, config *configuration.Configuration, ) error { - if config.Data.EndAtTip { + if config.Data.EndCondition.EndAtTip { // runs a go routine that ends when reaching tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay, EndAtTipCheckInterval) } - if config.Data.EndDuration != "" { - dur, err := time.ParseDuration(config.Data.EndDuration) + if config.Data.EndCondition.EndDuration != "" { + dur, err := time.ParseDuration(config.Data.EndCondition.EndDuration) if err != nil { log.Fatalf( "%s: invalid during string for EndDuration", From d54354e6f5d4e11d086dce0d9b902f093dc10377 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 12:21:59 -0700 Subject: [PATCH 09/15] Make EndDuration in seconds to be consistent with other time related configuration --- configuration/configuration.go | 4 ++-- internal/tester/data.go | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 79ed7464..fbbb5f2a 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -250,8 +250,8 @@ type EndCondition struct { EndAtTip bool `json:"end_at_tip"` // EndDuration is an end condtion that dictates how long the - // check:data command would be running for - EndDuration string `json:"end_duration"` + // check:data command would be running for in seconds + EndDuration uint64 `json:"end_duration"` } // DataConfiguration contains all configurations to run check:data. diff --git a/internal/tester/data.go b/internal/tester/data.go index 7d831491..e353edba 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -309,16 +309,9 @@ func (t *DataTester) WatchEndConditions( go t.syncer.EndAtTipLoop(ctx, config.TipDelay, EndAtTipCheckInterval) } - if config.Data.EndCondition.EndDuration != "" { - dur, err := time.ParseDuration(config.Data.EndCondition.EndDuration) - if err != nil { - log.Fatalf( - "%s: invalid during string for EndDuration", - err.Error(), - ) - } + if config.Data.EndCondition.EndDuration != 0 { // runs a go routine that ends after a duration - go t.syncer.EndDurationLoop(ctx, dur) + go t.syncer.EndDurationLoop(ctx, time.Duration(config.Data.EndCondition.EndDuration)*time.Second) } return nil From d1761c3d8d88640938ae65fd66cd3390f02f5bfb Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 12:22:58 -0700 Subject: [PATCH 10/15] nits --- configuration/configuration.go | 2 +- internal/statefulsyncer/stateful_syncer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index fbbb5f2a..1f94f3f4 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -249,7 +249,7 @@ type EndCondition struct { // EndAtTip determines if syncer should stop once it reached the tip EndAtTip bool `json:"end_at_tip"` - // EndDuration is an end condtion that dictates how long the + // EndDuration is an end condition that dictates how long the // check:data command would be running for in seconds EndDuration uint64 `json:"end_duration"` } diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index 2cf8ddc2..908d22be 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -230,7 +230,7 @@ func (s *StatefulSyncer) EndDurationLoop( case <-t.C: log.Printf( - "syncer has reached end condtion after %d seconds", + "syncer has reached end condition after %d seconds", int(duration.Seconds()), ) s.cancel() From 562feeda27b0df5dabf70b6f661a2c59fcd31a52 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 13:47:20 -0700 Subject: [PATCH 11/15] Add end condition to examples --- examples/configuration/default.json | 6 +++++- examples/configuration/simple.json | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/configuration/default.json b/examples/configuration/default.json index 8a4b5836..13d96a19 100644 --- a/examples/configuration/default.json +++ b/examples/configuration/default.json @@ -81,6 +81,10 @@ "interesting_accounts": "", "reconciliation_disabled": false, "inactive_discrepency_search_disabled": false, - "balance_tracking_disabled": false + "balance_tracking_disabled": false, + "end_condition": { + "end_at_tip": false, + "end_duration": 0 + } } } \ No newline at end of file diff --git a/examples/configuration/simple.json b/examples/configuration/simple.json index f186998d..34266384 100644 --- a/examples/configuration/simple.json +++ b/examples/configuration/simple.json @@ -13,6 +13,10 @@ "historical_balance_disabled": true, "reconciliation_disabled": true, "inactive_discrepency_search_disabled": true, - "balance_tracking_disabled": true + "balance_tracking_disabled": true, + "end_condition": { + "end_at_tip": true, + "end_duration": 7200 + } } } From 4be2bd1b5087fae7bb13ba46004ea0129028cd04 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 15:01:15 -0700 Subject: [PATCH 12/15] Rename EndCondition to EndConditions --- configuration/configuration.go | 6 +++--- examples/configuration/default.json | 2 +- examples/configuration/simple.json | 2 +- internal/tester/data.go | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 1f94f3f4..14e9fcbf 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -244,8 +244,8 @@ func DefaultConfiguration() *Configuration { } } -// EndCondition contains all the conditions for the syncer to stop. -type EndCondition struct { +// EndConditions contains all the conditions for the syncer to stop. +type EndConditions struct { // EndAtTip determines if syncer should stop once it reached the tip EndAtTip bool `json:"end_at_tip"` @@ -323,7 +323,7 @@ type DataConfiguration struct { BalanceTrackingDisabled bool `json:"balance_tracking_disabled"` // EndCondition contains the conditions for the syncer to stop - EndCondition EndCondition `json:"end_condition"` + EndConditions EndConditions `json:"end_conditions"` } // Configuration contains all configuration settings for running diff --git a/examples/configuration/default.json b/examples/configuration/default.json index 13d96a19..6eaa41f2 100644 --- a/examples/configuration/default.json +++ b/examples/configuration/default.json @@ -82,7 +82,7 @@ "reconciliation_disabled": false, "inactive_discrepency_search_disabled": false, "balance_tracking_disabled": false, - "end_condition": { + "end_conditions": { "end_at_tip": false, "end_duration": 0 } diff --git a/examples/configuration/simple.json b/examples/configuration/simple.json index 34266384..ef09290e 100644 --- a/examples/configuration/simple.json +++ b/examples/configuration/simple.json @@ -14,7 +14,7 @@ "reconciliation_disabled": true, "inactive_discrepency_search_disabled": true, "balance_tracking_disabled": true, - "end_condition": { + "end_conditions": { "end_at_tip": true, "end_duration": 7200 } diff --git a/internal/tester/data.go b/internal/tester/data.go index e353edba..7b8f0449 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -304,14 +304,14 @@ func (t *DataTester) WatchEndConditions( ctx context.Context, config *configuration.Configuration, ) error { - if config.Data.EndCondition.EndAtTip { + if config.Data.EndConditions.EndAtTip { // runs a go routine that ends when reaching tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay, EndAtTipCheckInterval) } - if config.Data.EndCondition.EndDuration != 0 { + if config.Data.EndConditions.EndDuration != 0 { // runs a go routine that ends after a duration - go t.syncer.EndDurationLoop(ctx, time.Duration(config.Data.EndCondition.EndDuration)*time.Second) + go t.syncer.EndDurationLoop(ctx, time.Duration(config.Data.EndConditions.EndDuration)*time.Second) } return nil From 1d978fa3c083d3511c06e846215405398b435cd1 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 15:03:56 -0700 Subject: [PATCH 13/15] Move EndAtTipCheckInterval to syncer --- internal/statefulsyncer/stateful_syncer.go | 11 +++++++++-- internal/tester/data.go | 8 +------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/statefulsyncer/stateful_syncer.go b/internal/statefulsyncer/stateful_syncer.go index 908d22be..e88d2ba3 100644 --- a/internal/statefulsyncer/stateful_syncer.go +++ b/internal/statefulsyncer/stateful_syncer.go @@ -29,6 +29,14 @@ import ( "github.com/coinbase/rosetta-sdk-go/types" ) +var ( + // EndAtTipCheckInterval is the frequency that EndAtTip condition + // is evaludated + // + // TODO: make configurable + EndAtTipCheckInterval = 10 * time.Second +) + var _ syncer.Handler = (*StatefulSyncer)(nil) var _ syncer.Helper = (*StatefulSyncer)(nil) @@ -186,9 +194,8 @@ func (s *StatefulSyncer) Block( func (s *StatefulSyncer) EndAtTipLoop( ctx context.Context, tipDelay int64, - interval time.Duration, ) { - tc := time.NewTicker(interval) + tc := time.NewTicker(EndAtTipCheckInterval) defer tc.Stop() for { diff --git a/internal/tester/data.go b/internal/tester/data.go index 7b8f0449..16badf2a 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -54,12 +54,6 @@ const ( // // TODO: make configurable PeriodicLoggingFrequency = 10 * time.Second - - // EndAtTipCheckInterval is the frequency that EndAtTip condition - // is evaludated - // - // TODO: make configurable - EndAtTipCheckInterval = 10 * time.Second ) // DataTester coordinates the `check:data` test. @@ -306,7 +300,7 @@ func (t *DataTester) WatchEndConditions( ) error { if config.Data.EndConditions.EndAtTip { // runs a go routine that ends when reaching tip - go t.syncer.EndAtTipLoop(ctx, config.TipDelay, EndAtTipCheckInterval) + go t.syncer.EndAtTipLoop(ctx, config.TipDelay) } if config.Data.EndConditions.EndDuration != 0 { From efe27b83830bb4d6a2c6dd4624b2ca2eb3624987 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 15:11:03 -0700 Subject: [PATCH 14/15] Make EndConditions a pointer --- configuration/configuration.go | 2 +- internal/tester/data.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 14e9fcbf..4b66abec 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -323,7 +323,7 @@ type DataConfiguration struct { BalanceTrackingDisabled bool `json:"balance_tracking_disabled"` // EndCondition contains the conditions for the syncer to stop - EndConditions EndConditions `json:"end_conditions"` + EndConditions *EndConditions `json:"end_conditions,omitempty"` } // Configuration contains all configuration settings for running diff --git a/internal/tester/data.go b/internal/tester/data.go index 16badf2a..93044960 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -298,14 +298,19 @@ func (t *DataTester) WatchEndConditions( ctx context.Context, config *configuration.Configuration, ) error { - if config.Data.EndConditions.EndAtTip { + endCond := config.Data.EndConditions + if endCond == nil { + return nil + } + + if endCond.EndAtTip { // runs a go routine that ends when reaching tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay) } - if config.Data.EndConditions.EndDuration != 0 { + if endCond.EndDuration != 0 { // runs a go routine that ends after a duration - go t.syncer.EndDurationLoop(ctx, time.Duration(config.Data.EndConditions.EndDuration)*time.Second) + go t.syncer.EndDurationLoop(ctx, time.Duration(endCond.EndDuration)*time.Second) } return nil From 61d591fc39ac0f6c1b9557073c134469b4f59e53 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 7 Aug 2020 15:12:13 -0700 Subject: [PATCH 15/15] nits --- internal/tester/data.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/tester/data.go b/internal/tester/data.go index 93044960..951e8509 100644 --- a/internal/tester/data.go +++ b/internal/tester/data.go @@ -298,19 +298,19 @@ func (t *DataTester) WatchEndConditions( ctx context.Context, config *configuration.Configuration, ) error { - endCond := config.Data.EndConditions - if endCond == nil { + endConds := config.Data.EndConditions + if endConds == nil { return nil } - if endCond.EndAtTip { + if endConds.EndAtTip { // runs a go routine that ends when reaching tip go t.syncer.EndAtTipLoop(ctx, config.TipDelay) } - if endCond.EndDuration != 0 { + if endConds.EndDuration != 0 { // runs a go routine that ends after a duration - go t.syncer.EndDurationLoop(ctx, time.Duration(endCond.EndDuration)*time.Second) + go t.syncer.EndDurationLoop(ctx, time.Duration(endConds.EndDuration)*time.Second) } return nil