// Copyright 2022 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . package rawdb import ( "bytes" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/rlp" "github.com/harmony-one/harmony/internal/utils" ) // ReadSkeletonSyncStatus retrieves the serialized sync status saved at shutdown. func ReadSkeletonSyncStatus(db ethdb.KeyValueReader) []byte { data, _ := db.Get(skeletonSyncStatusKey) return data } // WriteSkeletonSyncStatus stores the serialized sync status to save at shutdown. func WriteSkeletonSyncStatus(db ethdb.KeyValueWriter, status []byte) { if err := db.Put(skeletonSyncStatusKey, status); err != nil { utils.Logger().Error().Err(err).Msg("Failed to store skeleton sync status") } } // DeleteSkeletonSyncStatus deletes the serialized sync status saved at the last // shutdown func DeleteSkeletonSyncStatus(db ethdb.KeyValueWriter) { if err := db.Delete(skeletonSyncStatusKey); err != nil { utils.Logger().Error().Err(err).Msg("Failed to remove skeleton sync status") } } // ReadSkeletonHeader retrieves a block header from the skeleton sync store, func ReadSkeletonHeader(db ethdb.KeyValueReader, number uint64) *types.Header { data, _ := db.Get(skeletonHeaderKey(number)) if len(data) == 0 { return nil } header := new(types.Header) if err := rlp.Decode(bytes.NewReader(data), header); err != nil { utils.Logger().Error().Err(err).Uint64("number", number).Msg("Invalid skeleton header RLP") return nil } return header } // WriteSkeletonHeader stores a block header into the skeleton sync store. func WriteSkeletonHeader(db ethdb.KeyValueWriter, header *types.Header) { data, err := rlp.EncodeToBytes(header) if err != nil { utils.Logger().Error().Err(err).Msg("Failed to RLP encode header") } key := skeletonHeaderKey(header.Number.Uint64()) if err := db.Put(key, data); err != nil { utils.Logger().Error().Err(err).Msg("Failed to store skeleton header") } } // DeleteSkeletonHeader removes all block header data associated with a hash. func DeleteSkeletonHeader(db ethdb.KeyValueWriter, number uint64) { if err := db.Delete(skeletonHeaderKey(number)); err != nil { utils.Logger().Error().Err(err).Msg("Failed to delete skeleton header") } }