From 880a5e7c9bf2ed18d8bee8d34c3f8857d697dc91 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sat, 12 May 2018 11:44:05 -0400 Subject: [PATCH] sharding: all relevant tests pass, linter passes, ready for review #100 Former-commit-id: 9ab2595c130922bc49fc3c9a69f11dd93b6774fb [formerly 32c501eddb94d5dbfab61550cfa8705be7b8e59b] Former-commit-id: cfe18a1247e11e07d951e5038bf45d67e15d0bdf --- sharding/shard.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sharding/shard.go b/sharding/shard.go index de1734093..0b00c4c45 100644 --- a/sharding/shard.go +++ b/sharding/shard.go @@ -77,8 +77,8 @@ func (s *Shard) CollationByHash(headerHash *common.Hash) (*Collation, error) { return &Collation{header: header, body: body}, nil } -// CanonicalHeaderHash gets a collation header hash that has been set as canonical for -// shardID/period pair +// CanonicalHeaderHash gets a collation header hash that has been set as +// canonical for shardID/period pair func (s *Shard) CanonicalHeaderHash(shardID *big.Int, period *big.Int) (*common.Hash, error) { key := canonicalCollationLookupKey(shardID, period) @@ -129,6 +129,7 @@ func (s *Shard) CheckAvailability(header *CollationHeader) (bool, error) { if err != nil { return false, fmt.Errorf("key not found: %v", key) } + // availability is a byte array of length 1. return availability[0] != 0, nil } @@ -168,6 +169,7 @@ func (s *Shard) SaveBody(body []byte) error { // chunkRoot := getChunkRoot(body) using the blob algorithm utils. // right now we will just take the raw keccak256 of the body until #92 is merged. chunkRoot := common.BytesToHash(body) + if err := s.shardDB.Put(chunkRoot, body); err != nil { return fmt.Errorf("cannot update shardDB: %v", err) } @@ -215,7 +217,7 @@ func (s *Shard) SetCanonical(header *CollationHeader) error { // dataAvailabilityLookupKey formats a string that will become a lookup // key in the shardDB. func dataAvailabilityLookupKey(chunkRoot *common.Hash) common.Hash { - key := fmt.Sprintf("availability-lookup:%s", chunkRoot.Str()) + key := fmt.Sprintf("availability-lookup:%s", chunkRoot.String()) return common.BytesToHash([]byte(key)) }