forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epoch.go
47 lines (41 loc) · 1.67 KB
/
epoch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package aura
import (
"context"
libcommon "github.com/nebojsa94/erigon/erigon-lib/common"
"github.com/nebojsa94/erigon/erigon-lib/kv"
"github.com/nebojsa94/erigon/core/rawdb"
)
type NonTransactionalEpochReader struct {
db kv.RwDB
}
func newEpochReader(db kv.RwDB) *NonTransactionalEpochReader {
return &NonTransactionalEpochReader{db: db}
}
func (cr *NonTransactionalEpochReader) GetEpoch(hash libcommon.Hash, number uint64) (v []byte, err error) {
return v, cr.db.View(context.Background(), func(tx kv.Tx) error {
v, err = rawdb.ReadEpoch(tx, number, hash)
return err
})
}
func (cr *NonTransactionalEpochReader) PutEpoch(hash libcommon.Hash, number uint64, proof []byte) error {
return cr.db.UpdateNosync(context.Background(), func(tx kv.RwTx) error {
return rawdb.WriteEpoch(tx, number, hash, proof)
})
}
func (cr *NonTransactionalEpochReader) GetPendingEpoch(hash libcommon.Hash, number uint64) (v []byte, err error) {
return v, cr.db.View(context.Background(), func(tx kv.Tx) error {
v, err = rawdb.ReadPendingEpoch(tx, number, hash)
return err
})
}
func (cr *NonTransactionalEpochReader) PutPendingEpoch(hash libcommon.Hash, number uint64, proof []byte) error {
return cr.db.UpdateNosync(context.Background(), func(tx kv.RwTx) error {
return rawdb.WritePendingEpoch(tx, number, hash, proof)
})
}
func (cr *NonTransactionalEpochReader) FindBeforeOrEqualNumber(number uint64) (blockNum uint64, blockHash libcommon.Hash, transitionProof []byte, err error) {
return blockNum, blockHash, transitionProof, cr.db.View(context.Background(), func(tx kv.Tx) error {
blockNum, blockHash, transitionProof, err = rawdb.FindEpochBeforeOrEqualNumber(tx, number)
return err
})
}