Skip to content

Commit

Permalink
feat:rawdb about snap sync schema
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Nov 3, 2024
1 parent cf6cfc6 commit d36a813
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
40 changes: 40 additions & 0 deletions database/rawdb/accessors_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,43 @@ func WriteSnapshotSyncStatus(db ethdb.KeyValueWriter, status []byte) {
log.Error("Failed to store snapshot sync status", "err", err)
}
}

// snaputxo

func ReadSnapUtxo(db ethdb.Reader, opd []byte) []byte {
data, err := db.Get(snapUTXOKey(opd))
if len(data) == 0 {
if isErrWithoutNotFound(err) {
log.Error("read utxo", "err", err.Error())
}
return nil
}
return data
}

func WriteSnapUtxo(db ethdb.KeyValueWriter, opd []byte, data []byte) error {
if len(data) <= 0 {
return nil
}
return db.Put(snapUTXOKey(opd), data)
}

func DeleteSnapUtxo(db ethdb.KeyValueWriter, opd []byte) {
if err := db.Delete(snapUTXOKey(opd)); err != nil {
log.Crit("Failed to delete hash to utxo mapping", "err", err)
}
}

func ForeachSnapUtxo(db ethdb.KeyValueStore, fn func(opd []byte, data []byte) error) error {
it := db.NewIterator(SnapUTXOPrefix, nil)
defer it.Release()

for it.Next() {
op := it.Key()[len(SnapUTXOPrefix):]
err := fn(op, it.Value())
if err != nil {
return err
}
}
return nil
}
6 changes: 6 additions & 0 deletions database/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var (
// snapshot
SnapshotBlockOrderPrefix = []byte("o") // SnapshotBlockOrderPrefix + block order -> block id
SnapshotBlockStatusPrefix = []byte("s") // SnapshotBlockStatusPrefix + block id -> block status
SnapUTXOPrefix = []byte("U") // snaputxoPrefix + outpoint data -> UtxoEntry data

// EstimateFeeDatabaseKey is the key that we use to
// store the fee estimator in the database.
Expand Down Expand Up @@ -164,3 +165,8 @@ func invalidtxLookupKey(hash *hash.Hash) []byte {
func invalidtxFullHashKey(hash *hash.Hash) []byte {
return append(invalidtxFullHashPrefix, hash.Bytes()...)
}

// utxoKey = utxoPrefix + outpoint data
func snapUTXOKey(opd []byte) []byte {
return append(SnapUTXOPrefix, opd...)
}
2 changes: 1 addition & 1 deletion p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func NewService(cfg *config.Config, consensus model.Consensus, param *params.Par
bc := consensus.BlockChain().(*blockchain.BlockChain)
services := defaultServices
if bc.MeerChain().SyncMode() == downloader.SnapSync {
services |= pv.Snap
//services |= pv.Snap
}
s := &Service{
cfg: &common.Config{
Expand Down

0 comments on commit d36a813

Please sign in to comment.