Skip to content

Commit da53523

Browse files
author
Bernhard Scholz
committed
Fix differentiate between objects and IDs for lachesis
1 parent 6d66ff5 commit da53523

File tree

87 files changed

+334
-334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+334
-334
lines changed

cmd/sonictool/app/chain.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ func exportEvents(ctx *cli.Context) error {
4141
defer writer.(*gzip.Writer).Close()
4242
}
4343

44-
from := idx.Epoch(1)
44+
from := idx.EpochID(1)
4545
if len(ctx.Args()) > 1 {
4646
n, err := strconv.ParseUint(ctx.Args().Get(1), 10, 32)
4747
if err != nil {
4848
return err
4949
}
50-
from = idx.Epoch(n)
50+
from = idx.EpochID(n)
5151
}
52-
to := idx.Epoch(0)
52+
to := idx.EpochID(0)
5353
if len(ctx.Args()) > 2 {
5454
n, err := strconv.ParseUint(ctx.Args().Get(2), 10, 32)
5555
if err != nil {
5656
return err
5757
}
58-
to = idx.Epoch(n)
58+
to = idx.EpochID(n)
5959
}
6060

6161
gdbParams := db.GossipDbParameters{

cmd/sonictool/app/heal.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func heal(ctx *cli.Context) error {
7474
cancelCtx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
7575
defer stop()
7676

77-
recoveredBlock, err := db.HealChaindata(chaindataDir, cacheRatio, cfg, idx.Block(archiveCheckpointBlock))
77+
recoveredBlock, err := db.HealChaindata(chaindataDir, cacheRatio, cfg, idx.BlockID(archiveCheckpointBlock))
7878
if err != nil {
7979
return err
8080
}
@@ -93,7 +93,7 @@ func heal(ctx *cli.Context) error {
9393
return nil
9494
}
9595

96-
func healLiveFromArchive(ctx context.Context, carmenLiveDir, carmenArchiveDir string, recoveredBlock idx.Block) error {
96+
func healLiveFromArchive(ctx context.Context, carmenLiveDir, carmenArchiveDir string, recoveredBlock idx.BlockID) error {
9797
if err := os.RemoveAll(carmenLiveDir); err != nil {
9898
return fmt.Errorf("failed to remove broken live state: %w", err)
9999
}

cmd/sonictool/chain/export_events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
// always print out progress. This avoids the user wondering what's going on.
2525
const statsReportLimit = 8 * time.Second
2626

27-
func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, from, to idx.Epoch) (err error) {
27+
func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, from, to idx.EpochID) (err error) {
2828
chaindataDir := filepath.Join(gdbParams.DataDir, "chaindata")
2929
dbs, err := db.MakeDbProducer(chaindataDir, cachescale.Identity)
3030
if err != nil {

cmd/sonictool/chain/import_events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func importEventsFile(srv *gossip.Service, fn string) error {
120120
batch := make(inter.EventPayloads, 0, 8*1024)
121121
batchSize := 0
122122
maxBatchSize := 8 * 1024 * 1024
123-
epoch := idx.Epoch(0)
123+
epoch := idx.EpochID(0)
124124
txs := 0
125125
events := 0
126126

cmd/sonictool/check/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func checkArchiveBlockRoots(dataDir string, cacheRatio cachescale.Func) error {
4343

4444
invalidBlocks := 0
4545
lastBlockIdx := gdb.GetLatestBlockIndex()
46-
for i := idx.Block(1); i <= lastBlockIdx; i++ {
46+
for i := idx.BlockID(1); i <= lastBlockIdx; i++ {
4747
block := gdb.GetBlock(i)
4848
if block == nil {
4949
return fmt.Errorf("verification failed - unable to get block %d from gdb", i)

cmd/sonictool/db/heal.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121
)
2222

23-
func HealChaindata(chaindataDir string, cacheRatio cachescale.Func, cfg *config.Config, lastCarmenBlock idx.Block) (idx.Block, error) {
23+
func HealChaindata(chaindataDir string, cacheRatio cachescale.Func, cfg *config.Config, lastCarmenBlock idx.BlockID) (idx.BlockID, error) {
2424
producer := &DummyScopedProducer{integration.GetRawDbProducer(chaindataDir, integration.DBCacheConfig{
2525
Cache: cacheRatio.U64(480 * opt.MiB),
2626
Fdlimit: makeDatabaseHandles(),
@@ -43,7 +43,7 @@ func HealChaindata(chaindataDir string, cacheRatio cachescale.Func, cfg *config.
4343
if err != nil {
4444
return 0, fmt.Errorf("failed to open 'lachesis' database: %w", err)
4545
}
46-
cGetEpochDB := func(epoch idx.Epoch) kvdb.Store {
46+
cGetEpochDB := func(epoch idx.EpochID) kvdb.Store {
4747
name := fmt.Sprintf("lachesis-%d", epoch)
4848
cEpochDB, err := producer.OpenDB(name)
4949
if err != nil {
@@ -71,8 +71,8 @@ func HealChaindata(chaindataDir string, cacheRatio cachescale.Func, cfg *config.
7171
}
7272

7373
// healGossipDb reverts the gossip database into state, into which can be reverted carmen
74-
func healGossipDb(producer kvdb.FlushableDBProducer, cfg gossip.StoreConfig, lastCarmenBlock idx.Block) (
75-
epochState *iblockproc.EpochState, lastBlock idx.Block, err error) {
74+
func healGossipDb(producer kvdb.FlushableDBProducer, cfg gossip.StoreConfig, lastCarmenBlock idx.BlockID) (
75+
epochState *iblockproc.EpochState, lastBlock idx.BlockID, err error) {
7676

7777
gdb, err := gossip.NewStore(producer, cfg) // requires FlushIDKey present (not clean) in all dbs
7878
if err != nil {
@@ -106,10 +106,10 @@ func healGossipDb(producer kvdb.FlushableDBProducer, cfg gossip.StoreConfig, las
106106
}
107107

108108
// getLastEpochWithState finds the last closed epoch with the state available
109-
func getLastEpochWithState(gdb *gossip.Store, lastCarmenBlock idx.Block) (epochIdx idx.Epoch, blockState *iblockproc.BlockState, epochState *iblockproc.EpochState) {
109+
func getLastEpochWithState(gdb *gossip.Store, lastCarmenBlock idx.BlockID) (epochIdx idx.EpochID, blockState *iblockproc.BlockState, epochState *iblockproc.EpochState) {
110110
currentEpoch := gdb.GetEpoch()
111-
epochsToTry := idx.Epoch(10000)
112-
endEpoch := idx.Epoch(1)
111+
epochsToTry := idx.EpochID(10000)
112+
endEpoch := idx.EpochID(1)
113113
if currentEpoch > epochsToTry {
114114
endEpoch = currentEpoch - epochsToTry
115115
}

cmd/sonictool/genesis/export.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func ExportGenesis(ctx context.Context, gdb *gossip.Store, includeArchive bool,
8282
return nil
8383
}
8484

85-
func exportEpochsSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter, from, to idx.Epoch) error {
85+
func exportEpochsSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter, from, to idx.EpochID) error {
8686
log.Info("Exporting epochs", "from", from, "to", to)
8787
for i := to; i >= from; i-- {
8888
er := gdb.GetFullEpochRecord(i)
@@ -111,15 +111,15 @@ func exportEpochsSection(ctx context.Context, gdb *gossip.Store, writer *unitWri
111111
return nil
112112
}
113113

114-
func exportBlocksSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter, to idx.Block, maxBlocks int64) error {
114+
func exportBlocksSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter, to idx.BlockID, maxBlocks int64) error {
115115
toBlock := int64(to)
116116
fromBlock := int64(0)
117117
if maxBlocks != 0 && toBlock > 1+maxBlocks {
118118
fromBlock = toBlock - maxBlocks
119119
}
120120
log.Info("Exporting blocks", "from", fromBlock, "to", toBlock)
121121
for i := toBlock; i >= fromBlock; i-- {
122-
i := idx.Block(i)
122+
i := idx.BlockID(i)
123123
br := gdb.GetFullBlockRecord(i)
124124
if br == nil {
125125
return fmt.Errorf("the block record for block %d is missing in gdb", i)
@@ -177,7 +177,7 @@ func exportFwaSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter
177177
return nil
178178
}
179179

180-
func getEpochBlock(epoch idx.Epoch, store *gossip.Store) idx.Block {
180+
func getEpochBlock(epoch idx.EpochID, store *gossip.Store) idx.BlockID {
181181
bs, _ := store.GetHistoryBlockEpochState(epoch)
182182
if bs == nil {
183183
return 0

cmd/sonictool/genesis/import.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func ImportGenesisStore(params ImportParams) error {
6060
if err != nil {
6161
return err
6262
}
63-
cGetEpochDB := func(epoch idx.Epoch) kvdb.Store {
63+
cGetEpochDB := func(epoch idx.EpochID) kvdb.Store {
6464
db, err := dbs.OpenDB(fmt.Sprintf("lachesis-%d", epoch))
6565
if err != nil {
6666
panic(fmt.Errorf("failed to open epoch db: %w", err))

config/make_node.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func MakeNode(ctx *cli.Context, cfg *Config) (*node.Node, *gossip.Service, func(
118118
}
119119
return evmcore.NewTxPool(cfg.TxPool, reader.Config(), reader)
120120
}
121-
haltCheck := func(oldEpoch, newEpoch idx.Epoch, age time.Time) bool {
121+
haltCheck := func(oldEpoch, newEpoch idx.EpochID, age time.Time) bool {
122122
stop := ctx.GlobalIsSet(flags.ExitWhenAgeFlag.Name) && ctx.GlobalDuration(flags.ExitWhenAgeFlag.Name) >= time.Since(age)
123-
stop = stop || ctx.GlobalIsSet(flags.ExitWhenEpochFlag.Name) && idx.Epoch(ctx.GlobalUint64(flags.ExitWhenEpochFlag.Name)) <= newEpoch
123+
stop = stop || ctx.GlobalIsSet(flags.ExitWhenEpochFlag.Name) && idx.EpochID(ctx.GlobalUint64(flags.ExitWhenEpochFlag.Name)) <= newEpoch
124124
if stop {
125125
go func() {
126126
// do it in a separate thread to avoid deadlock

ethapi/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexO
133133
return nil, err
134134
}
135135
oldest := last
136-
if oldest > idx.Block(blockCount) {
137-
oldest -= idx.Block(blockCount - 1)
136+
if oldest > idx.BlockID(blockCount) {
137+
oldest -= idx.BlockID(blockCount - 1)
138138
} else {
139139
oldest = 0
140140
}

ethapi/backend.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ import (
4141

4242
// PeerProgress is synchronization status of a peer
4343
type PeerProgress struct {
44-
CurrentEpoch idx.Epoch
45-
CurrentBlock idx.Block
44+
CurrentEpoch idx.EpochID
45+
CurrentBlock idx.BlockID
4646
CurrentBlockHash hash.Event
4747
CurrentBlockTime inter.Timestamp
48-
HighestBlock idx.Block
49-
HighestEpoch idx.Epoch
48+
HighestBlock idx.BlockID
49+
HighestEpoch idx.EpochID
5050
}
5151

5252
// Backend interface provides the common API services (that are provided by
@@ -70,7 +70,7 @@ type Backend interface {
7070
HeaderByHash(ctx context.Context, hash common.Hash) (*evmcore.EvmHeader, error)
7171
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmBlock, error)
7272
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (state.StateDB, *evmcore.EvmHeader, error)
73-
ResolveRpcBlockNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (idx.Block, error)
73+
ResolveRpcBlockNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (idx.BlockID, error)
7474
BlockByHash(ctx context.Context, hash common.Hash) (*evmcore.EvmBlock, error)
7575
GetReceiptsByNumber(ctx context.Context, number rpc.BlockNumber) (types.Receipts, error)
7676
GetEVM(ctx context.Context, msg *core.Message, state vm.StateDB, header *evmcore.EvmHeader, vmConfig *vm.Config) (*vm.EVM, func() error, error)
@@ -95,12 +95,12 @@ type Backend interface {
9595
GetEventPayload(ctx context.Context, shortEventID string) (*inter.EventPayload, error)
9696
GetEvent(ctx context.Context, shortEventID string) (*inter.Event, error)
9797
GetHeads(ctx context.Context, epoch rpc.BlockNumber) (hash.Events, error)
98-
CurrentEpoch(ctx context.Context) idx.Epoch
98+
CurrentEpoch(ctx context.Context) idx.EpochID
9999
SealedEpochTiming(ctx context.Context) (start inter.Timestamp, end inter.Timestamp)
100100

101101
// Lachesis aBFT API
102102
GetEpochBlockState(ctx context.Context, epoch rpc.BlockNumber) (*iblockproc.BlockState, *iblockproc.EpochState, error)
103-
GetDowntime(ctx context.Context, vid idx.ValidatorID) (idx.Block, inter.Timestamp, error)
103+
GetDowntime(ctx context.Context, vid idx.ValidatorID) (idx.BlockID, inter.Timestamp, error)
104104
GetUptime(ctx context.Context, vid idx.ValidatorID) (*big.Int, error)
105105
GetOriginatedFee(ctx context.Context, vid idx.ValidatorID) (*big.Int, error)
106106
}

ethapi/mock_backend.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eventcheck/epochcheck/epoch_check.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
// Reader returns currents epoch and its validators group.
2727
type Reader interface {
2828
base.Reader
29-
GetEpochRules() (opera.Rules, idx.Epoch)
29+
GetEpochRules() (opera.Rules, idx.EpochID)
3030
}
3131

3232
// Checker which require only current epoch info
@@ -51,8 +51,8 @@ func CalcGasPowerUsed(e inter.EventPayloadI, rules opera.Rules) uint64 {
5151
gasCfg := rules.Economy.Gas
5252

5353
parentsGas := uint64(0)
54-
if idx.Event(len(e.Parents())) > rules.Dag.MaxFreeParents {
55-
parentsGas = uint64(idx.Event(len(e.Parents()))-rules.Dag.MaxFreeParents) * gasCfg.ParentGas
54+
if idx.EventID(len(e.Parents())) > rules.Dag.MaxFreeParents {
55+
parentsGas = uint64(idx.EventID(len(e.Parents()))-rules.Dag.MaxFreeParents) * gasCfg.ParentGas
5656
}
5757
extraGas := uint64(len(e.Extra())) * gasCfg.ExtraDataGas
5858

@@ -110,7 +110,7 @@ func (v *Checker) Validate(e inter.EventPayloadI) error {
110110
if e.Epoch() != epoch {
111111
return base.ErrNotRelevant
112112
}
113-
if idx.Event(len(e.Parents())) > rules.Dag.MaxParents {
113+
if idx.EventID(len(e.Parents())) > rules.Dag.MaxParents {
114114
return ErrTooManyParents
115115
}
116116
if uint32(len(e.Extra())) > rules.Dag.MaxExtraData {

eventcheck/gaspowercheck/gas_power_check.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type ValidatorState struct {
2626

2727
// ValidationContext for gaspower checking
2828
type ValidationContext struct {
29-
Epoch idx.Epoch
29+
Epoch idx.EpochID
3030
Configs [inter.GasPowerConfigs]Config
3131
EpochStart inter.Timestamp
3232
Validators *ltypes.Validators

eventcheck/heavycheck/heavy_check.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ var (
2626

2727
// Reader is accessed by the validator to get the current state.
2828
type Reader interface {
29-
GetEpochPubKeys() (map[idx.ValidatorID]validatorpk.PubKey, idx.Epoch)
30-
GetEpochPubKeysOf(idx.Epoch) map[idx.ValidatorID]validatorpk.PubKey
31-
GetEpochBlockStart(idx.Epoch) idx.Block
29+
GetEpochPubKeys() (map[idx.ValidatorID]validatorpk.PubKey, idx.EpochID)
30+
GetEpochPubKeysOf(idx.EpochID) map[idx.ValidatorID]validatorpk.PubKey
31+
GetEpochBlockStart(idx.EpochID) idx.BlockID
3232
}
3333

3434
// Checker which requires only parents list + current epoch info
@@ -105,7 +105,7 @@ func verifySignature(signedHash hash.Hash, sig inter.Signature, pubkey validator
105105
return crypto.VerifySignature(pubkey.Raw, signedHash.Bytes(), sig.Bytes())
106106
}
107107

108-
func (v *Checker) ValidateEventLocator(e inter.SignedEventLocator, authEpoch idx.Epoch, authErr error, checkPayload func() bool) error {
108+
func (v *Checker) ValidateEventLocator(e inter.SignedEventLocator, authEpoch idx.EpochID, authErr error, checkPayload func() bool) error {
109109
pubkeys := v.reader.GetEpochPubKeysOf(authEpoch)
110110
if len(pubkeys) == 0 {
111111
return authErr

evmcore/dummy_block.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type (
5252

5353
PrevRandao common.Hash // == mixHash/mixDigest
5454

55-
Epoch idx.Epoch
55+
Epoch idx.EpochID
5656
}
5757

5858
EvmBlock struct {

0 commit comments

Comments
 (0)