diff options
author | Ting-Wei Lan <tingwei.lan@cobinhood.com> | 2019-03-26 15:31:56 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:04 +0800 |
commit | b72d7b04bba7ce3a3117b61b15cad3c40e19f1c0 (patch) | |
tree | b9239a6c6642206862ac81de5ba02a5cd419f4d6 | |
parent | b46e4244ab17b696674cb3e263fe407e557e8127 (diff) | |
download | dexon-b72d7b04bba7ce3a3117b61b15cad3c40e19f1c0.tar.gz dexon-b72d7b04bba7ce3a3117b61b15cad3c40e19f1c0.tar.zst dexon-b72d7b04bba7ce3a3117b61b15cad3c40e19f1c0.zip |
core: vm: sqlvm: use common.HashLength instead of 32
Keep them consisitent with ast/types.go.
-rw-r--r-- | core/vm/sqlvm/common/storage.go | 10 | ||||
-rw-r--r-- | core/vm/sqlvm/common/storage_test.go | 6 | ||||
-rw-r--r-- | core/vm/sqlvm/schema/schema.go | 3 |
3 files changed, 10 insertions, 9 deletions
diff --git a/core/vm/sqlvm/common/storage.go b/core/vm/sqlvm/common/storage.go index 4595a773b..674efbf17 100644 --- a/core/vm/sqlvm/common/storage.go +++ b/core/vm/sqlvm/common/storage.go @@ -78,15 +78,15 @@ func getDByteSize(data common.Hash) uint64 { func (s Storage) DecodeDByteBySlot(address common.Address, slot common.Hash) []byte { data := s.GetState(address, slot) length := getDByteSize(data) - if length < 32 { + if length < common.HashLength { return data[:length] } ptr := crypto.Keccak256Hash(slot.Bytes()) - slotNum := (length-1)/32 + 1 - rVal := make([]byte, slotNum*32) + slotNum := (length-1)/common.HashLength + 1 + rVal := make([]byte, slotNum*common.HashLength) for i := uint64(0); i < slotNum; i++ { - start := i * 32 - copy(rVal[start:start+32], s.GetState(address, ptr).Bytes()) + start := i * common.HashLength + copy(rVal[start:start+common.HashLength], s.GetState(address, ptr).Bytes()) ptr = s.ShiftHashUint64(ptr, 1) } return rVal[:length] diff --git a/core/vm/sqlvm/common/storage_test.go b/core/vm/sqlvm/common/storage_test.go index 42b8c2298..3a7633496 100644 --- a/core/vm/sqlvm/common/storage_test.go +++ b/core/vm/sqlvm/common/storage_test.go @@ -84,11 +84,11 @@ func SetDataToStateDB(head common.Hash, storage Storage, addr common.Address, b := t.slotData.Bytes() if b[len(b)-1]&0x1 != 0 { length := len(t.result) - slotNum := (length-1)/32 + 1 + slotNum := (length-1)/common.HashLength + 1 ptr := crypto.Keccak256Hash(slot.Bytes()) for s := 0; s < slotNum; s++ { - start := s * 32 - end := (s + 1) * 32 + start := s * common.HashLength + end := (s + 1) * common.HashLength if end > len(t.result) { end = len(t.result) } diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go index f2a46631d..d77cd3855 100644 --- a/core/vm/sqlvm/schema/schema.go +++ b/core/vm/sqlvm/schema/schema.go @@ -6,6 +6,7 @@ import ( "github.com/shopspring/decimal" + "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/vm/sqlvm/ast" se "github.com/dexon-foundation/dexon/core/vm/sqlvm/errors" "github.com/dexon-foundation/dexon/rlp" @@ -136,7 +137,7 @@ func (t *Table) SetupColumnOffset() { byteOffset := uint8(0) for i, col := range t.Columns { size := col.Type.Size() - if size+byteOffset > 32 { + if size+byteOffset > common.HashLength { slotOffset++ byteOffset = 0 } |