sharding: use .Hex() instead of .String() when logging hexdigests

Former-commit-id: 09695f12e61a3f25fa1830a445861119d236078d [formerly e79627c2af202768419df470cdc49e1a3f6cb826]
Former-commit-id: bbda4b36cceb25e765c05299d2ce96b7a6e4b275
This commit is contained in:
Raul Jordan 2018-05-16 09:49:41 -04:00
parent 54875f5389
commit 9b3a32221c
2 changed files with 7 additions and 13 deletions

View File

@ -52,7 +52,7 @@ func (s *Shard) HeaderByHash(hash *common.Hash) (*CollationHeader, error) {
return nil, fmt.Errorf("get failed: %v", err) return nil, fmt.Errorf("get failed: %v", err)
} }
if encoded == nil { if encoded == nil {
return nil, fmt.Errorf("no value set for header hash: %v", hash.String()) return nil, fmt.Errorf("no value set for header hash: %vs", hash.Hex())
} }
var header CollationHeader var header CollationHeader
@ -158,10 +158,7 @@ func (s *Shard) SetAvailability(chunkRoot *common.Hash, availability bool) error
} else { } else {
encoded = []byte{0} encoded = []byte{0}
} }
if err := s.shardDB.Put(key, encoded); err != nil { return s.shardDB.Put(key, encoded)
return err
}
return nil
} }
// SaveHeader adds the collation header to shardDB. // SaveHeader adds the collation header to shardDB.
@ -177,10 +174,7 @@ func (s *Shard) SaveHeader(header *CollationHeader) error {
} }
// uses the hash of the header as the key. // uses the hash of the header as the key.
if err := s.shardDB.Put(header.Hash(), encoded); err != nil { return s.shardDB.Put(header.Hash(), encoded)
return fmt.Errorf("cannot update shardDB: %v", err)
}
return nil
} }
// SaveBody adds the collation body to the shardDB and sets availability. // SaveBody adds the collation body to the shardDB and sets availability.
@ -245,7 +239,7 @@ func (s *Shard) SetCanonical(header *CollationHeader) error {
// dataAvailabilityLookupKey formats a string that will become a lookup // dataAvailabilityLookupKey formats a string that will become a lookup
// key in the shardDB. // key in the shardDB.
func dataAvailabilityLookupKey(chunkRoot *common.Hash) common.Hash { func dataAvailabilityLookupKey(chunkRoot *common.Hash) common.Hash {
key := fmt.Sprintf("availability-lookup:%s", chunkRoot.String()) key := fmt.Sprintf("availability-lookup:%s", chunkRoot.Hex())
return common.BytesToHash([]byte(key)) return common.BytesToHash([]byte(key))
} }

View File

@ -191,8 +191,8 @@ func TestShard_CanonicalHeaderHash(t *testing.T) {
t.Errorf("should throw error if a non-existent period, shardID pair is used") t.Errorf("should throw error if a non-existent period, shardID pair is used")
} }
if canonicalHeaderHash.String() != headerHash.String() { if canonicalHeaderHash.Hex() != headerHash.Hex() {
t.Errorf("header hashes do not match. want=%s. got=%s", headerHash.String(), canonicalHeaderHash.String()) t.Errorf("header hashes do not match. want=%s. got=%s", headerHash.Hex(), canonicalHeaderHash.Hex())
} }
} }
@ -337,7 +337,7 @@ func TestShard_CheckAvailability(t *testing.T) {
t.Errorf("could not check availability: %v", err) t.Errorf("could not check availability: %v", err)
} }
if !available { if !available {
t.Errorf("collation body is not available: chunkRoot=%v, body=%v", header.ChunkRoot(), collation.body) t.Errorf("collation body is not available: chunkRoot=%s, body=%v", header.ChunkRoot().Hex(), collation.body)
} }
} }