From 63802e98e7e30c3af93a6dcc5dd6e87237ddd9c6 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sat, 12 May 2018 11:27:32 -0400 Subject: [PATCH] sharding: finished remaining test bodies, now just need to pass Former-commit-id: 73f723be47a60743b7bca0fa469dd11f014e5fe6 [formerly 98fa2928954ce5bbb9228b2a9fa89c09807cf7d9] Former-commit-id: 194afc9fb5c10f35a5783de462e6877e2446e471 --- sharding/shard.go | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/sharding/shard.go b/sharding/shard.go index 8eca64482..de1734093 100644 --- a/sharding/shard.go +++ b/sharding/shard.go @@ -125,39 +125,24 @@ func (s *Shard) BodyByChunkRoot(chunkRoot *common.Hash) ([]byte, error) { // CheckAvailability is used by notaries to confirm a header's data availability. func (s *Shard) CheckAvailability(header *CollationHeader) (bool, error) { key := dataAvailabilityLookupKey(header.ChunkRoot()) - availabilityVal, err := s.shardDB.Get(key) + availability, err := s.shardDB.Get(key) if err != nil { return false, fmt.Errorf("key not found: %v", key) } - var availability int - if err := rlp.DecodeBytes(availabilityVal, &availability); err != nil { - return false, fmt.Errorf("cannot RLP decode availability: %v", err) - } - if availability != 0 { - return true, nil - } - return false, nil + return availability[0] != 0, nil } // SetAvailability saves the availability of the chunk root in the shardDB. func (s *Shard) SetAvailability(chunkRoot *common.Hash, availability bool) error { key := dataAvailabilityLookupKey(chunkRoot) + var encoded []byte if availability { - enc, err := rlp.EncodeToBytes(true) - if err != nil { - return fmt.Errorf("cannot RLP encode availability: %v", err) - } - if err := s.shardDB.Put(key, enc); err != nil { - return fmt.Errorf("cannot update shardDB: %v", err) - } + encoded = []byte{1} } else { - enc, err := rlp.EncodeToBytes(false) - if err != nil { - return fmt.Errorf("cannot RLP encode availability: %v", err) - } - if err := s.shardDB.Put(key, enc); err != nil { - return fmt.Errorf("cannot update shardDB: %v", err) - } + encoded = []byte{0} + } + if err := s.shardDB.Put(key, encoded); err != nil { + return fmt.Errorf("cannot update shardDB: %v", err) } return nil }