From 9b3a32221cd2a591628b08e241515f6e15aabab0 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 16 May 2018 09:49:41 -0400 Subject: [PATCH] sharding: use .Hex() instead of .String() when logging hexdigests Former-commit-id: 09695f12e61a3f25fa1830a445861119d236078d [formerly e79627c2af202768419df470cdc49e1a3f6cb826] Former-commit-id: bbda4b36cceb25e765c05299d2ce96b7a6e4b275 --- sharding/shard.go | 14 ++++---------- sharding/shard_test.go | 6 +++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/sharding/shard.go b/sharding/shard.go index 816ca2c84..fb38cc829 100644 --- a/sharding/shard.go +++ b/sharding/shard.go @@ -52,7 +52,7 @@ func (s *Shard) HeaderByHash(hash *common.Hash) (*CollationHeader, error) { return nil, fmt.Errorf("get failed: %v", err) } 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 @@ -158,10 +158,7 @@ func (s *Shard) SetAvailability(chunkRoot *common.Hash, availability bool) error } else { encoded = []byte{0} } - if err := s.shardDB.Put(key, encoded); err != nil { - return err - } - return nil + return s.shardDB.Put(key, encoded) } // 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. - if err := s.shardDB.Put(header.Hash(), encoded); err != nil { - return fmt.Errorf("cannot update shardDB: %v", err) - } - return nil + return s.shardDB.Put(header.Hash(), encoded) } // 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 // key in the shardDB. 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)) } diff --git a/sharding/shard_test.go b/sharding/shard_test.go index 4c174a200..cd3d90af5 100644 --- a/sharding/shard_test.go +++ b/sharding/shard_test.go @@ -191,8 +191,8 @@ func TestShard_CanonicalHeaderHash(t *testing.T) { t.Errorf("should throw error if a non-existent period, shardID pair is used") } - if canonicalHeaderHash.String() != headerHash.String() { - t.Errorf("header hashes do not match. want=%s. got=%s", headerHash.String(), canonicalHeaderHash.String()) + if canonicalHeaderHash.Hex() != headerHash.Hex() { + 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) } 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) } }