From 912e95edc8bd40af7e374540bef78d860d62eae7 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Sat, 8 Aug 2020 13:43:27 -0700 Subject: [PATCH 1/4] Add tests for omitted blocks to block storage --- go.mod | 2 +- go.sum | 2 ++ pkg/storage/block_storage_test.go | 43 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b77e12c8..e8f40475 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/coinbase/rosetta-cli go 1.13 require ( - github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200807162047-31075a509b1f + github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200808203554-be8e8fc68ebe github.com/dgraph-io/badger/v2 v2.0.3 github.com/dgraph-io/ristretto v0.0.2 // indirect github.com/ethereum/go-ethereum v1.9.18 diff --git a/go.sum b/go.sum index 4c800806..13edc217 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk 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.20200807162047-31075a509b1f h1:U69ZwbTR10diY1MDi9LP/RxetVJzjd4bvIDUEs8XYvk= github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200807162047-31075a509b1f/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ= +github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200808203554-be8e8fc68ebe h1:qFvooSvGBzzrhDi+KifU8b+hrLiw2ZjDOVREcABPBS8= +github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200808203554-be8e8fc68ebe/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ= 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= diff --git a/pkg/storage/block_storage_test.go b/pkg/storage/block_storage_test.go index 8f9a55e1..1ce348fc 100644 --- a/pkg/storage/block_storage_test.go +++ b/pkg/storage/block_storage_test.go @@ -247,6 +247,17 @@ var ( simpleTransactionFactory("blahTx3", "addr2", "200", &types.Currency{Symbol: "hello"}), }, } + + gapBlock = &types.Block{ + BlockIdentifier: &types.BlockIdentifier{ + Hash: "block 10", + Index: 10, + }, + ParentBlockIdentifier: &types.BlockIdentifier{ + Hash: "blah 3", + Index: 3, + }, + } ) func findTransactionWithDbTransaction( @@ -402,6 +413,20 @@ func TestBlock(t *testing.T) { assert.NoError(t, err) assert.Equal(t, complexBlock.BlockIdentifier, head) }) + + t.Run("Add block after omitted", func(t *testing.T) { + err := storage.AddBlock(ctx, gapBlock) + assert.NoError(t, err) + + block, err := storage.GetBlock(ctx, gapBlock.BlockIdentifier) + assert.NoError(t, err) + assert.Equal(t, gapBlock, block) + + head, err := storage.GetHeadBlockIdentifier(ctx) + assert.NoError(t, err) + assert.Equal(t, gapBlock.BlockIdentifier, head) + }) + } func TestCreateBlockCache(t *testing.T) { @@ -440,6 +465,24 @@ func TestCreateBlockCache(t *testing.T) { storage.CreateBlockCache(ctx), ) }) + + t.Run("3 blocks processed (with gap)", func(t *testing.T) { + simpleGap := &types.Block{ + BlockIdentifier: &types.BlockIdentifier{ + Hash: "block 100", + Index: 100, + }, + ParentBlockIdentifier: newBlock.BlockIdentifier, + } + + err = storage.AddBlock(ctx, simpleGap) + assert.NoError(t, err) + assert.Equal( + t, + []*types.BlockIdentifier{genesisBlock.BlockIdentifier, newBlock.BlockIdentifier, simpleGap.BlockIdentifier}, + storage.CreateBlockCache(ctx), + ) + }) } func TestAtTip(t *testing.T) { From bad923eed8985c5e01b3fe3c87bfa1956715e532 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Sat, 8 Aug 2020 14:54:52 -0700 Subject: [PATCH 2/4] Add ability to fetch block by index --- pkg/storage/block_storage.go | 148 +++++++++++++++++------------- pkg/storage/block_storage_test.go | 43 +++++++-- 2 files changed, 122 insertions(+), 69 deletions(-) diff --git a/pkg/storage/block_storage.go b/pkg/storage/block_storage.go index ac5a59cf..a3dc31e6 100644 --- a/pkg/storage/block_storage.go +++ b/pkg/storage/block_storage.go @@ -35,11 +35,8 @@ const ( // blockNamespace is prepended to any stored block. blockNamespace = "block" - // blockHashNamespace is prepended to any stored block hash. - // We cannot just use the stored block key to lookup whether - // a hash has been used before because it is concatenated - // with the index of the stored block. - blockHashNamespace = "block-hash" + // blockIndexNamespace is prepended to any stored block index. + blockIndexNamespace = "block-index" // transactionHashNamespace is prepended to any stored // transaction hash. @@ -55,9 +52,9 @@ var ( // found in BlockStorage. ErrBlockNotFound = errors.New("block not found") - // ErrDuplicateBlockHash is returned when a block hash + // ErrDuplicateKey is returned when a key // cannot be stored because it is a duplicate. - ErrDuplicateBlockHash = errors.New("duplicate block hash") + ErrDuplicateKey = errors.New("duplicate key") // ErrDuplicateTransactionHash is returned when a transaction // hash cannot be stored because it is a duplicate. @@ -68,14 +65,12 @@ func getHeadBlockKey() []byte { return []byte(headBlockKey) } -func getBlockKey(blockIdentifier *types.BlockIdentifier) []byte { - return []byte( - fmt.Sprintf("%s/%s/%d", blockNamespace, blockIdentifier.Hash, blockIdentifier.Index), - ) +func getBlockHashKey(hash string) []byte { + return []byte(fmt.Sprintf("%s/%s", blockNamespace, hash)) } -func getBlockHashKey(blockIdentifier *types.BlockIdentifier) []byte { - return []byte(fmt.Sprintf("%s/%s", blockHashNamespace, blockIdentifier.Hash)) +func getBlockIndexKey(index int64) []byte { + return []byte(fmt.Sprintf("%s/%d", blockIndexNamespace, index)) } func getTransactionHashKey(transactionIdentifier *types.TransactionIdentifier) []byte { @@ -174,18 +169,38 @@ func (b *BlockStorage) StoreHeadBlockIdentifier( // GetBlock returns a block, if it exists. func (b *BlockStorage) GetBlock( ctx context.Context, - blockIdentifier *types.BlockIdentifier, + blockIdentifier *types.PartialBlockIdentifier, ) (*types.Block, error) { transaction := b.db.NewDatabaseTransaction(ctx, false) defer transaction.Discard(ctx) - exists, block, err := transaction.Get(ctx, getBlockKey(blockIdentifier)) + var exists bool + var block []byte + var err error + if blockIdentifier == nil || (blockIdentifier.Hash == nil && blockIdentifier.Index == nil) { + var head *types.BlockIdentifier + head, err = b.GetHeadBlockIdentifierTransactional(ctx, transaction) + if err != nil { + return nil, fmt.Errorf("%w: cannot get head block identifier", err) + } + + exists, block, err = transaction.Get(ctx, getBlockHashKey(head.Hash)) + } else if blockIdentifier.Hash != nil { + exists, block, err = transaction.Get(ctx, getBlockHashKey(*blockIdentifier.Hash)) + } else { + var blockKey []byte + exists, blockKey, err = transaction.Get(ctx, getBlockIndexKey(*blockIdentifier.Index)) + if exists { + exists, block, err = transaction.Get(ctx, blockKey) + } + } + if err != nil { - return nil, err + return nil, fmt.Errorf("%w: unable to get block", err) } if !exists { - return nil, fmt.Errorf("%w %+v", ErrBlockNotFound, blockIdentifier) + return nil, fmt.Errorf("%w: %+v", ErrBlockNotFound, blockIdentifier) } var rosettaBlock types.Block @@ -197,6 +212,27 @@ func (b *BlockStorage) GetBlock( return &rosettaBlock, nil } +func (b *BlockStorage) storeBlock(ctx context.Context, transaction DatabaseTransaction, block *types.Block) error { + buf, err := encode(block) + if err != nil { + return fmt.Errorf("%w: unable to encode block", err) + } + + if err := b.storeUniqueKey(ctx, transaction, getBlockHashKey(block.BlockIdentifier.Hash), buf); err != nil { + return fmt.Errorf("%w: unable to store block", err) + } + + if err := b.storeUniqueKey(ctx, transaction, getBlockIndexKey(block.BlockIdentifier.Index), getBlockHashKey(block.BlockIdentifier.Hash)); err != nil { + return fmt.Errorf("%w: unable to store block index", err) + } + + if err := b.StoreHeadBlockIdentifier(ctx, transaction, block.BlockIdentifier); err != nil { + return fmt.Errorf("%w: unable to update head block identifier", err) + } + + return nil +} + // AddBlock stores a block or returns an error. func (b *BlockStorage) AddBlock( ctx context.Context, @@ -205,25 +241,10 @@ func (b *BlockStorage) AddBlock( transaction := b.db.NewDatabaseTransaction(ctx, true) defer transaction.Discard(ctx) - buf, err := encode(block) - if err != nil { - return err - } - // Store block - err = transaction.Set(ctx, getBlockKey(block.BlockIdentifier), buf) + err := b.storeBlock(ctx, transaction, block) if err != nil { - return err - } - - if err = b.StoreHeadBlockIdentifier(ctx, transaction, block.BlockIdentifier); err != nil { - return err - } - - // Store block hash - err = b.storeBlockHash(ctx, transaction, block.BlockIdentifier) - if err != nil { - return fmt.Errorf("%w: unable to store block hash", err) + return fmt.Errorf("%w: unable to store block", err) } // Store all transaction hashes @@ -242,6 +263,23 @@ func (b *BlockStorage) AddBlock( return b.callWorkersAndCommit(ctx, block, transaction, true) } +func (b *BlockStorage) deleteBlock(ctx context.Context, transaction DatabaseTransaction, block *types.Block) error { + blockIdentifier := block.BlockIdentifier + if err := transaction.Delete(ctx, getBlockHashKey(blockIdentifier.Hash)); err != nil { + return fmt.Errorf("%w: unable to delete block", err) + } + + if err := transaction.Delete(ctx, getBlockIndexKey(blockIdentifier.Index)); err != nil { + return fmt.Errorf("%w: unable to delete block index", err) + } + + if err := b.StoreHeadBlockIdentifier(ctx, transaction, block.ParentBlockIdentifier); err != nil { + return fmt.Errorf("%w: unable to update head block identifier", err) + } + + return nil +} + // RemoveBlock removes a block or returns an error. // RemoveBlock also removes the block hash and all // its transaction hashes to not break duplicate @@ -250,7 +288,7 @@ func (b *BlockStorage) RemoveBlock( ctx context.Context, blockIdentifier *types.BlockIdentifier, ) error { - block, err := b.GetBlock(ctx, blockIdentifier) + block, err := b.GetBlock(ctx, types.ConstructPartialBlockIdentifier(blockIdentifier)) if err != nil { return err } @@ -266,19 +304,9 @@ func (b *BlockStorage) RemoveBlock( } } - // Remove block hash - err = transaction.Delete(ctx, getBlockHashKey(blockIdentifier)) - if err != nil { - return err - } - - // Remove block - if err := transaction.Delete(ctx, getBlockKey(blockIdentifier)); err != nil { - return err - } - - if err = b.StoreHeadBlockIdentifier(ctx, transaction, block.ParentBlockIdentifier); err != nil { - return err + // Delete block + if err := b.deleteBlock(ctx, transaction, block); err != nil { + return fmt.Errorf("%w: unable to delete block", err) } return b.callWorkersAndCommit(ctx, block, transaction, false) @@ -348,7 +376,7 @@ func (b *BlockStorage) SetNewStartIndex( currBlock := head for currBlock.Index >= startIndex { log.Printf("Removing block %+v\n", currBlock) - block, err := b.GetBlock(ctx, currBlock) + block, err := b.GetBlock(ctx, types.ConstructPartialBlockIdentifier(currBlock)) if err != nil { return err } @@ -373,7 +401,7 @@ func (b *BlockStorage) CreateBlockCache(ctx context.Context) []*types.BlockIdent } for len(cache) < syncer.PastBlockSize { - block, err := b.GetBlock(ctx, head) + block, err := b.GetBlock(ctx, types.ConstructPartialBlockIdentifier(head)) if err != nil { return cache } @@ -392,22 +420,22 @@ func (b *BlockStorage) CreateBlockCache(ctx context.Context) []*types.BlockIdent return cache } -func (b *BlockStorage) storeBlockHash( +func (b *BlockStorage) storeUniqueKey( ctx context.Context, transaction DatabaseTransaction, - block *types.BlockIdentifier, + key []byte, + value []byte, ) error { - hashKey := getBlockHashKey(block) - exists, _, err := transaction.Get(ctx, hashKey) + exists, _, err := transaction.Get(ctx, key) if err != nil { return err } if exists { - return fmt.Errorf("%w: duplicate block hash %s found", ErrDuplicateBlockHash, block.Hash) + return fmt.Errorf("%w: duplicate key %s found", ErrDuplicateKey, string(key)) } - return transaction.Set(ctx, hashKey, []byte("")) + return transaction.Set(ctx, key, value) } func (b *BlockStorage) storeTransactionHash( @@ -518,7 +546,7 @@ func (b *BlockStorage) FindTransaction( } } - blockExists, block, err := txn.Get(ctx, getBlockKey(newestBlock)) + blockExists, block, err := txn.Get(ctx, getBlockHashKey(newestBlock.Hash)) if err != nil { return nil, nil, fmt.Errorf("%w: unable to query database for block", err) } @@ -554,15 +582,11 @@ func (b *BlockStorage) AtTip( ctx context.Context, tipDelay int64, ) (bool, error) { - head, err := b.GetHeadBlockIdentifier(ctx) + block, err := b.GetBlock(ctx, nil) if errors.Is(err, ErrHeadBlockNotFound) { return false, nil } - if err != nil { - return false, fmt.Errorf("%w: unable to get head block identifir", err) - } - block, err := b.GetBlock(ctx, head) if err != nil { return false, fmt.Errorf("%w: unable to get head block", err) } diff --git a/pkg/storage/block_storage_test.go b/pkg/storage/block_storage_test.go index 1ce348fc..44970247 100644 --- a/pkg/storage/block_storage_test.go +++ b/pkg/storage/block_storage_test.go @@ -303,7 +303,15 @@ func TestBlock(t *testing.T) { err := storage.AddBlock(ctx, newBlock) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, newBlock.BlockIdentifier) + block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(newBlock.BlockIdentifier)) + assert.NoError(t, err) + assert.Equal(t, newBlock, block) + + block, err = storage.GetBlock(ctx, &types.PartialBlockIdentifier{Index: &newBlock.BlockIdentifier.Index}) + assert.NoError(t, err) + assert.Equal(t, newBlock, block) + + block, err = storage.GetBlock(ctx, nil) assert.NoError(t, err) assert.Equal(t, newBlock, block) @@ -322,25 +330,46 @@ func TestBlock(t *testing.T) { }) t.Run("Get non-existent block", func(t *testing.T) { - block, err := storage.GetBlock(ctx, badBlockIdentifier) + identifier := types.ConstructPartialBlockIdentifier(badBlockIdentifier) + block, err := storage.GetBlock(ctx, identifier) assert.EqualError( t, err, - fmt.Errorf("%w %+v", ErrBlockNotFound, badBlockIdentifier).Error(), + fmt.Errorf("%w: %+v", ErrBlockNotFound, identifier).Error(), + ) + assert.Nil(t, block) + }) + + t.Run("Get non-existent block index", func(t *testing.T) { + badIndex := int64(100000) + identifier := &types.PartialBlockIdentifier{Index: &badIndex} + block, err := storage.GetBlock(ctx, identifier) + assert.EqualError( + t, + err, + fmt.Errorf("%w: %+v", ErrBlockNotFound, identifier).Error(), ) assert.Nil(t, block) }) t.Run("Set duplicate block hash", func(t *testing.T) { err = storage.AddBlock(ctx, newBlock) - assert.Contains(t, err.Error(), ErrDuplicateBlockHash.Error()) + assert.Contains(t, err.Error(), ErrDuplicateKey.Error()) }) t.Run("Set duplicate transaction hash (from prior block)", func(t *testing.T) { err = storage.AddBlock(ctx, newBlock2) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, newBlock2.BlockIdentifier) + block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(newBlock2.BlockIdentifier)) + assert.NoError(t, err) + assert.Equal(t, newBlock2, block) + + block, err = storage.GetBlock(ctx, &types.PartialBlockIdentifier{Index: &newBlock2.BlockIdentifier.Index}) + assert.NoError(t, err) + assert.Equal(t, newBlock2, block) + + block, err = storage.GetBlock(ctx, nil) assert.NoError(t, err) assert.Equal(t, newBlock2, block) @@ -387,7 +416,7 @@ func TestBlock(t *testing.T) { err := storage.AddBlock(ctx, complexBlock) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, complexBlock.BlockIdentifier) + block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(complexBlock.BlockIdentifier)) assert.NoError(t, err) assert.Equal(t, complexBlock, block) @@ -418,7 +447,7 @@ func TestBlock(t *testing.T) { err := storage.AddBlock(ctx, gapBlock) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, gapBlock.BlockIdentifier) + block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(gapBlock.BlockIdentifier)) assert.NoError(t, err) assert.Equal(t, gapBlock, block) From 30beca7190defde3049f3d119ccf106f3f58cefd Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Sat, 8 Aug 2020 15:01:33 -0700 Subject: [PATCH 3/4] Nits --- pkg/processor/reconciler_helper.go | 2 +- pkg/storage/block_storage.go | 29 ++++++++++++++++++----- pkg/storage/block_storage_test.go | 37 +++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/pkg/processor/reconciler_helper.go b/pkg/processor/reconciler_helper.go index 85ef8bc9..e98b9f9c 100644 --- a/pkg/processor/reconciler_helper.go +++ b/pkg/processor/reconciler_helper.go @@ -49,7 +49,7 @@ func (h *ReconcilerHelper) BlockExists( ctx context.Context, block *types.BlockIdentifier, ) (bool, error) { - _, err := h.blockStorage.GetBlock(ctx, block) + _, err := h.blockStorage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(block)) if err == nil { return true, nil } diff --git a/pkg/storage/block_storage.go b/pkg/storage/block_storage.go index a3dc31e6..133cbdd2 100644 --- a/pkg/storage/block_storage.go +++ b/pkg/storage/block_storage.go @@ -177,7 +177,9 @@ func (b *BlockStorage) GetBlock( var exists bool var block []byte var err error - if blockIdentifier == nil || (blockIdentifier.Hash == nil && blockIdentifier.Index == nil) { + switch { + case blockIdentifier == nil || (blockIdentifier.Hash == nil && blockIdentifier.Index == nil): + // Get current block when no blockIdentifier is provided var head *types.BlockIdentifier head, err = b.GetHeadBlockIdentifierTransactional(ctx, transaction) if err != nil { @@ -185,9 +187,11 @@ func (b *BlockStorage) GetBlock( } exists, block, err = transaction.Get(ctx, getBlockHashKey(head.Hash)) - } else if blockIdentifier.Hash != nil { + case blockIdentifier.Hash != nil: + // Get block by hash if provided exists, block, err = transaction.Get(ctx, getBlockHashKey(*blockIdentifier.Hash)) - } else { + default: + // Get block by index if hash not provided var blockKey []byte exists, blockKey, err = transaction.Get(ctx, getBlockIndexKey(*blockIdentifier.Index)) if exists { @@ -212,7 +216,11 @@ func (b *BlockStorage) GetBlock( return &rosettaBlock, nil } -func (b *BlockStorage) storeBlock(ctx context.Context, transaction DatabaseTransaction, block *types.Block) error { +func (b *BlockStorage) storeBlock( + ctx context.Context, + transaction DatabaseTransaction, + block *types.Block, +) error { buf, err := encode(block) if err != nil { return fmt.Errorf("%w: unable to encode block", err) @@ -222,7 +230,12 @@ func (b *BlockStorage) storeBlock(ctx context.Context, transaction DatabaseTrans return fmt.Errorf("%w: unable to store block", err) } - if err := b.storeUniqueKey(ctx, transaction, getBlockIndexKey(block.BlockIdentifier.Index), getBlockHashKey(block.BlockIdentifier.Hash)); err != nil { + if err := b.storeUniqueKey( + ctx, + transaction, + getBlockIndexKey(block.BlockIdentifier.Index), + getBlockHashKey(block.BlockIdentifier.Hash), + ); err != nil { return fmt.Errorf("%w: unable to store block index", err) } @@ -263,7 +276,11 @@ func (b *BlockStorage) AddBlock( return b.callWorkersAndCommit(ctx, block, transaction, true) } -func (b *BlockStorage) deleteBlock(ctx context.Context, transaction DatabaseTransaction, block *types.Block) error { +func (b *BlockStorage) deleteBlock( + ctx context.Context, + transaction DatabaseTransaction, + block *types.Block, +) error { blockIdentifier := block.BlockIdentifier if err := transaction.Delete(ctx, getBlockHashKey(blockIdentifier.Hash)); err != nil { return fmt.Errorf("%w: unable to delete block", err) diff --git a/pkg/storage/block_storage_test.go b/pkg/storage/block_storage_test.go index 44970247..b7f4a5da 100644 --- a/pkg/storage/block_storage_test.go +++ b/pkg/storage/block_storage_test.go @@ -303,11 +303,17 @@ func TestBlock(t *testing.T) { err := storage.AddBlock(ctx, newBlock) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(newBlock.BlockIdentifier)) + block, err := storage.GetBlock( + ctx, + types.ConstructPartialBlockIdentifier(newBlock.BlockIdentifier), + ) assert.NoError(t, err) assert.Equal(t, newBlock, block) - block, err = storage.GetBlock(ctx, &types.PartialBlockIdentifier{Index: &newBlock.BlockIdentifier.Index}) + block, err = storage.GetBlock( + ctx, + &types.PartialBlockIdentifier{Index: &newBlock.BlockIdentifier.Index}, + ) assert.NoError(t, err) assert.Equal(t, newBlock, block) @@ -361,11 +367,17 @@ func TestBlock(t *testing.T) { err = storage.AddBlock(ctx, newBlock2) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(newBlock2.BlockIdentifier)) + block, err := storage.GetBlock( + ctx, + types.ConstructPartialBlockIdentifier(newBlock2.BlockIdentifier), + ) assert.NoError(t, err) assert.Equal(t, newBlock2, block) - block, err = storage.GetBlock(ctx, &types.PartialBlockIdentifier{Index: &newBlock2.BlockIdentifier.Index}) + block, err = storage.GetBlock( + ctx, + &types.PartialBlockIdentifier{Index: &newBlock2.BlockIdentifier.Index}, + ) assert.NoError(t, err) assert.Equal(t, newBlock2, block) @@ -416,7 +428,10 @@ func TestBlock(t *testing.T) { err := storage.AddBlock(ctx, complexBlock) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(complexBlock.BlockIdentifier)) + block, err := storage.GetBlock( + ctx, + types.ConstructPartialBlockIdentifier(complexBlock.BlockIdentifier), + ) assert.NoError(t, err) assert.Equal(t, complexBlock, block) @@ -447,7 +462,10 @@ func TestBlock(t *testing.T) { err := storage.AddBlock(ctx, gapBlock) assert.NoError(t, err) - block, err := storage.GetBlock(ctx, types.ConstructPartialBlockIdentifier(gapBlock.BlockIdentifier)) + block, err := storage.GetBlock( + ctx, + types.ConstructPartialBlockIdentifier(gapBlock.BlockIdentifier), + ) assert.NoError(t, err) assert.Equal(t, gapBlock, block) @@ -455,7 +473,6 @@ func TestBlock(t *testing.T) { assert.NoError(t, err) assert.Equal(t, gapBlock.BlockIdentifier, head) }) - } func TestCreateBlockCache(t *testing.T) { @@ -508,7 +525,11 @@ func TestCreateBlockCache(t *testing.T) { assert.NoError(t, err) assert.Equal( t, - []*types.BlockIdentifier{genesisBlock.BlockIdentifier, newBlock.BlockIdentifier, simpleGap.BlockIdentifier}, + []*types.BlockIdentifier{ + genesisBlock.BlockIdentifier, + newBlock.BlockIdentifier, + simpleGap.BlockIdentifier, + }, storage.CreateBlockCache(ctx), ) }) From e455c22ff9ae0d18f49b3af4ccc2603e6f8a4349 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Sun, 9 Aug 2020 15:29:21 -0700 Subject: [PATCH 4/4] Use rosetta-sdk-go@v0.3.4 --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index e8f40475..739101ef 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/coinbase/rosetta-cli go 1.13 require ( - github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200808203554-be8e8fc68ebe + github.com/coinbase/rosetta-sdk-go v0.3.4 github.com/dgraph-io/badger/v2 v2.0.3 github.com/dgraph-io/ristretto v0.0.2 // indirect github.com/ethereum/go-ethereum v1.9.18 diff --git a/go.sum b/go.sum index 13edc217..8d6831d8 100644 --- a/go.sum +++ b/go.sum @@ -54,10 +54,8 @@ 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.20200807162047-31075a509b1f h1:U69ZwbTR10diY1MDi9LP/RxetVJzjd4bvIDUEs8XYvk= -github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200807162047-31075a509b1f/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ= -github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200808203554-be8e8fc68ebe h1:qFvooSvGBzzrhDi+KifU8b+hrLiw2ZjDOVREcABPBS8= -github.com/coinbase/rosetta-sdk-go v0.3.4-0.20200808203554-be8e8fc68ebe/go.mod h1:Q6dAY0kdG2X3jNaIYnkxnZOb8XEZQar9Q1RcnBgm/wQ= +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/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=