From de2eeb46711cbd750722eb7e9f5010b3e6b60916 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 1 Nov 2019 20:13:00 +0300 Subject: [PATCH] rpc: add one to the block height for the getblockcount response There is a difference in interpretation of what a block count is. neo-go nodes currently respond to this request with the latest block number which is the same number that neoscan.io shows. However, C# nodes deliberately do add one to this number when answering to the getblockcount request to account for the genesis block number 0. This patch makes us consistent with C# nodes wrt to getblockcount behaviour. --- pkg/rpc/server.go | 2 +- pkg/rpc/server_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/rpc/server.go b/pkg/rpc/server.go index 93d767f1a..2fe141fe4 100644 --- a/pkg/rpc/server.go +++ b/pkg/rpc/server.go @@ -157,7 +157,7 @@ Methods: results = wrappers.NewBlock(block, s.chain) case "getblockcount": getblockcountCalled.Inc() - results = s.chain.BlockHeight() + results = s.chain.BlockHeight() + 1 case "getblockhash": getblockHashCalled.Inc() diff --git a/pkg/rpc/server_test.go b/pkg/rpc/server_test.go index 1f6424d72..533dd6f04 100644 --- a/pkg/rpc/server_test.go +++ b/pkg/rpc/server_test.go @@ -51,7 +51,7 @@ func TestRPC(t *testing.T) { var res IntResultResponse err := json.Unmarshal(bytes.TrimSpace(body), &res) assert.NoErrorf(t, err, "could not parse response: %s", body) - assert.Equal(t, chain.BlockHeight(), uint32(res.Result)) + assert.Equal(t, chain.BlockHeight()+1, uint32(res.Result)) }) t.Run("getblockhash", func(t *testing.T) {