Skip to content

Commit

Permalink
Merge pull request #114 from coinbase/patrick/fix-construction-api-head
Browse files Browse the repository at this point in the history
[BUG] Ensure block synced before starting Construction API Testing Loop
  • Loading branch information
patrick-ogrady committed Aug 19, 2020
2 parents 874018b + 6b136bf commit ad66cdb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/coinbase/rosetta-cli
go 1.13

require (
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200819052137-5d2bf966818b
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200819181259-3eff56cab108
github.com/fatih/color v1.9.0
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ 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 h1:jWKgajozco/T0FNnZb2TqBsmsUoF6ZuCLnUJkEE+vNg=
github.com/coinbase/rosetta-sdk-go v0.3.4/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ=
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200819052137-5d2bf966818b h1:JSV23Q51pp5SEKEQ0ZspXevVz5xNdsCIpW786pVUf7g=
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200819052137-5d2bf966818b/go.mod h1:7y6tIrUHdxBAS0kshqdHZXyi0CQ+O9s+Itmodzxs7IQ=
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200819181259-3eff56cab108 h1:mW8fci/qMy7Jl5QjvMf1dkm+UKqoJnciCbyiLXcJeQo=
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200819181259-3eff56cab108/go.mod h1:7y6tIrUHdxBAS0kshqdHZXyi0CQ+O9s+Itmodzxs7IQ=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand Down Expand Up @@ -138,6 +142,11 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26 h1:lMm2hD9Fy0ynom5+85/pbdkiYcBqM1JWmhpAXLmy0fw=
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/addlicense v0.0.0-20200622132530-df58acafd6d5 h1:m6Z1Cm53o4VecQFxKCnvULGfIT0Igo3MX131i+00IIo=
github.com/google/addlicense v0.0.0-20200622132530-df58acafd6d5/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA=
github.com/google/addlicense v0.0.0-20200815122332-4295bd52e3cf h1:YE2N9S5+KJNPjtA0uTxDgtfZ7U7/Ia0IkKI5bCUYcp8=
github.com/google/addlicense v0.0.0-20200815122332-4295bd52e3cf/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA=
github.com/google/addlicense v0.0.0-20200817051935-6f4cd4aacc89 h1:oTppmscIAQ2Y1tcsMDcTLR3z4MN/96/pvIsBSLGl7o8=
github.com/google/addlicense v0.0.0-20200817051935-6f4cd4aacc89/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -253,6 +262,7 @@ github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9Ac
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/segmentio/golines v0.0.0-20200306054842-869934f8da7b/go.mod h1:K7zjgP8yJ/U8nb8nxaSykalAKSvbqr6TNbd9B7zzBFU=
github.com/segmentio/golines v0.0.0-20200808004416-0a9796b248e8/go.mod h1:bQSh5qdVR67XiCKbaVvYO41s50c5hQo+3cY/1CQQ3xQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v2.20.5+incompatible h1:tYH07UPoQt0OCQdgWWMgYHy3/a9bcxNpBIysykNIP7I=
Expand Down Expand Up @@ -360,6 +370,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
14 changes: 0 additions & 14 deletions mocks/constructor/handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions mocks/constructor/helper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/constructor/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ type Helper interface {

// RandomAmount returns some integer between min and max.
RandomAmount(*big.Int, *big.Int) *big.Int

// HeadBlockExists returns a boolean indicating if a block
// has been synced by BlockStorage.
HeadBlockExists(context.Context) bool
}

// Handler is an interface called by the constructor whenever
Expand Down Expand Up @@ -914,6 +918,15 @@ func (c *Constructor) CreateTransactions(
}

for ctx.Err() == nil {
if !c.helper.HeadBlockExists(ctx) {
// We will sleep until at least one block has been synced.
// Many of the storage-based commands require a synced block
// to work correctly (i.e. when fetching a balance, a block
// must be returned).
time.Sleep(defaultSleepTime * time.Second)
continue
}

sender, balance, coinIdentifier, err := c.findSender(ctx)
if err != nil {
return fmt.Errorf("%w: unable to find sender", err)
Expand Down
11 changes: 11 additions & 0 deletions pkg/processor/constructor_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ConstructorHelper struct {
offlineFetcher *fetcher.Fetcher
onlineFetcher *fetcher.Fetcher

blockStorage *storage.BlockStorage
keyStorage *storage.KeyStorage
balanceStorage *storage.BalanceStorage
coinStorage *storage.CoinStorage
Expand All @@ -46,6 +47,7 @@ type ConstructorHelper struct {
func NewConstructorHelper(
offlineFetcher *fetcher.Fetcher,
onlineFetcher *fetcher.Fetcher,
blockStorage *storage.BlockStorage,
keyStorage *storage.KeyStorage,
balanceStorage *storage.BalanceStorage,
coinStorage *storage.CoinStorage,
Expand All @@ -54,6 +56,7 @@ func NewConstructorHelper(
return &ConstructorHelper{
offlineFetcher: offlineFetcher,
onlineFetcher: onlineFetcher,
blockStorage: blockStorage,
keyStorage: keyStorage,
balanceStorage: balanceStorage,
coinStorage: coinStorage,
Expand Down Expand Up @@ -267,3 +270,11 @@ func (c *ConstructorHelper) AllAddresses(ctx context.Context) ([]string, error)
func (c *ConstructorHelper) RandomAmount(min *big.Int, max *big.Int) *big.Int {
return utils.RandomNumber(min, max)
}

// HeadBlockExists returns a boolean indicating if a block has been
// synced by BlockStorage.
func (c *ConstructorHelper) HeadBlockExists(ctx context.Context) bool {
headBlock, _ := c.blockStorage.GetHeadBlockIdentifier(ctx)

return headBlock != nil
}
1 change: 1 addition & 0 deletions pkg/tester/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func InitializeConstruction(
constructorHelper := processor.NewConstructorHelper(
offlineFetcher,
onlineFetcher,
blockStorage,
keyStorage,
balanceStorage,
coinStorage,
Expand Down

0 comments on commit ad66cdb

Please sign in to comment.