sharding: finished remaining test bodies, now just need to pass

Former-commit-id: 73f723be47a60743b7bca0fa469dd11f014e5fe6 [formerly 98fa2928954ce5bbb9228b2a9fa89c09807cf7d9]
Former-commit-id: 194afc9fb5c10f35a5783de462e6877e2446e471
This commit is contained in:
Raul Jordan 2018-05-12 11:27:32 -04:00
parent 7cb08abeca
commit 63802e98e7

View File

@ -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
}