diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 4e45d2aa9..5a4364b27 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -29,7 +29,7 @@ import ( // Tuning parameters. const ( headerBatchCount = 2000 - version = "0.0.4" + version = "0.0.5" // This one comes from C# code and it's different from the constant used // when creating an asset with Neo.Asset.Create interop call. It looks @@ -414,6 +414,7 @@ func (bc *Blockchain) processHeader(h *block.Header, batch storage.Batch, header } buf.Reset() + buf.BinWriter.WriteU32LE(0) // sys fee is yet to be calculated h.EncodeBinary(buf.BinWriter) if buf.Err != nil { return buf.Err @@ -949,7 +950,7 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error) { } } - block, err := bc.dao.GetBlock(hash) + block, _, err := bc.dao.GetBlock(hash) if err != nil { return nil, err } @@ -974,7 +975,7 @@ func (bc *Blockchain) GetHeader(hash util.Uint256) (*block.Header, error) { return tb.Header(), nil } } - block, err := bc.dao.GetBlock(hash) + block, _, err := bc.dao.GetBlock(hash) if err != nil { return nil, err } diff --git a/pkg/core/dao.go b/pkg/core/dao.go index d84e50816..124316abe 100644 --- a/pkg/core/dao.go +++ b/pkg/core/dao.go @@ -375,17 +375,18 @@ func makeStorageItemKey(scripthash util.Uint160, key []byte) []byte { // -- other. // GetBlock returns Block by the given hash if it exists in the store. -func (dao *dao) GetBlock(hash util.Uint256) (*block.Block, error) { +func (dao *dao) GetBlock(hash util.Uint256) (*block.Block, uint32, error) { key := storage.AppendPrefix(storage.DataBlock, hash.BytesLE()) b, err := dao.store.Get(key) if err != nil { - return nil, err + return nil, 0, err } - block, err := block.NewBlockFromTrimmedBytes(b) + + block, err := block.NewBlockFromTrimmedBytes(b[4:]) if err != nil { - return nil, err + return nil, 0, err } - return block, err + return block, binary.LittleEndian.Uint32(b[:4]), nil } // GetVersion attempts to get the current version stored in the @@ -508,8 +509,7 @@ func (dao *dao) StoreAsBlock(block *block.Block, sysFee uint32) error { key = storage.AppendPrefix(storage.DataBlock, block.Hash().BytesLE()) buf = io.NewBufBinWriter() ) - // sysFee needs to be handled somehow - // buf.WriteU32LE(sysFee) + buf.WriteU32LE(sysFee) b, err := block.Trim() if err != nil { return err diff --git a/pkg/core/dao_test.go b/pkg/core/dao_test.go index 3b4a30343..da2964c45 100644 --- a/pkg/core/dao_test.go +++ b/pkg/core/dao_test.go @@ -254,7 +254,7 @@ func TestDeleteStorageItem(t *testing.T) { func TestGetBlock_NotExists(t *testing.T) { dao := newDao(storage.NewMemoryStore()) hash := random.Uint256() - block, err := dao.GetBlock(hash) + block, _, err := dao.GetBlock(hash) require.Error(t, err) require.Nil(t, block) } @@ -270,11 +270,12 @@ func TestPutGetBlock(t *testing.T) { }, } hash := b.Hash() - err := dao.StoreAsBlock(b, 0) + err := dao.StoreAsBlock(b, 42) require.NoError(t, err) - gotBlock, err := dao.GetBlock(hash) + gotBlock, sysfee, err := dao.GetBlock(hash) require.NoError(t, err) require.NotNil(t, gotBlock) + require.EqualValues(t, 42, sysfee) } func TestGetVersion_NoVersion(t *testing.T) {