mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-01 15:57:39 +00:00
sharding: fetch body by chunk root
Former-commit-id: 5021890d223501bf163d6beae4e4e732673950d2 [formerly 92e89aed0c61909971cf9262cd3002bf2ae2328a] Former-commit-id: 0fd4497f880213878965107de3f782b44c33f065
This commit is contained in:
parent
84a2cb08d7
commit
1793e7d21d
@ -6,11 +6,11 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
type shardBackend struct {
|
||||
type shardKV struct {
|
||||
kv map[common.Hash][]byte
|
||||
}
|
||||
|
||||
func (sb *shardBackend) Get(k common.Hash) ([]byte, error) {
|
||||
func (sb *shardKV) Get(k common.Hash) ([]byte, error) {
|
||||
v := sb.kv[k]
|
||||
if v == nil {
|
||||
return nil, fmt.Errorf("Key Not Found")
|
||||
@ -18,12 +18,12 @@ func (sb *shardBackend) Get(k common.Hash) ([]byte, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (sb *shardBackend) Put(k common.Hash, v []byte) {
|
||||
func (sb *shardKV) Put(k common.Hash, v []byte) {
|
||||
sb.kv[k] = v
|
||||
return
|
||||
}
|
||||
|
||||
func (sb *shardBackend) Delete(k common.Hash) {
|
||||
func (sb *shardKV) Delete(k common.Hash) {
|
||||
delete(sb.kv, k)
|
||||
return
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Shard base struct.
|
||||
type Shard struct {
|
||||
shardDB *shardBackend
|
||||
shardDB *shardKV
|
||||
shardID *big.Int
|
||||
}
|
||||
|
||||
@ -22,8 +22,8 @@ func (s *Shard) ValidateShardID(h *CollationHeader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetHeader adds the collation header to shardDB
|
||||
func (s *Shard) SetHeader(h *CollationHeader) error {
|
||||
// SaveHeader adds the collation header to shardDB.
|
||||
func (s *Shard) SaveHeader(h *CollationHeader) error {
|
||||
if err := s.ValidateShardID(h); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -35,6 +35,15 @@ func (s *Shard) SetHeader(h *CollationHeader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveCollationBody adds the collation body to shardDB.
|
||||
func (s *Shard) SaveCollationBody(body []byte) error {
|
||||
// TODO: dependent on blob serialization.
|
||||
// chunkRoot := getChunkRoot(body) using the blob algorithm utils.
|
||||
// s.shardDB.Put(chunkRoot, body)
|
||||
// s.SetAvailability(chunkRoot, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetHeaderByHash of collation.
|
||||
func (s *Shard) GetHeaderByHash(hash common.Hash) (*CollationHeader, error) {
|
||||
encoded, err := s.shardDB.Get(hash)
|
||||
@ -61,7 +70,7 @@ func (s *Shard) GetCollationByHash(hash common.Hash) (*Collation, error) {
|
||||
return &Collation{header: header, body: body}, nil
|
||||
}
|
||||
|
||||
// GetBodyByChunkRoot fetches a collation body
|
||||
// GetBodyByChunkRoot fetches a collation body.
|
||||
func (s *Shard) GetBodyByChunkRoot(chunkRoot common.Hash) ([]byte, error) {
|
||||
body, err := s.shardDB.Get(chunkRoot)
|
||||
if err != nil {
|
||||
@ -75,7 +84,7 @@ func (s *Shard) CheckAvailability(header *CollationHeader) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// SetUnavailable ensures to set a collation as unavailable in the shardDB.
|
||||
func (s *Shard) SetUnavailable(header *CollationHeader) error {
|
||||
// SetAvailability saves the availability of the chunk root in the shardDB.
|
||||
func (s *Shard) SetAvailability(chunkRoot *common.Hash) error {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user