Skip to content

Commit

Permalink
Fix differentiate between objects and IDs for lachesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Scholz committed Dec 4, 2024
1 parent 6d66ff5 commit da53523
Show file tree
Hide file tree
Showing 87 changed files with 334 additions and 334 deletions.
8 changes: 4 additions & 4 deletions cmd/sonictool/app/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ func exportEvents(ctx *cli.Context) error {
defer writer.(*gzip.Writer).Close()
}

from := idx.Epoch(1)
from := idx.EpochID(1)
if len(ctx.Args()) > 1 {
n, err := strconv.ParseUint(ctx.Args().Get(1), 10, 32)
if err != nil {
return err
}
from = idx.Epoch(n)
from = idx.EpochID(n)
}
to := idx.Epoch(0)
to := idx.EpochID(0)
if len(ctx.Args()) > 2 {
n, err := strconv.ParseUint(ctx.Args().Get(2), 10, 32)
if err != nil {
return err
}
to = idx.Epoch(n)
to = idx.EpochID(n)
}

gdbParams := db.GossipDbParameters{
Expand Down
4 changes: 2 additions & 2 deletions cmd/sonictool/app/heal.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func heal(ctx *cli.Context) error {
cancelCtx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

recoveredBlock, err := db.HealChaindata(chaindataDir, cacheRatio, cfg, idx.Block(archiveCheckpointBlock))
recoveredBlock, err := db.HealChaindata(chaindataDir, cacheRatio, cfg, idx.BlockID(archiveCheckpointBlock))
if err != nil {
return err
}
Expand All @@ -93,7 +93,7 @@ func heal(ctx *cli.Context) error {
return nil
}

func healLiveFromArchive(ctx context.Context, carmenLiveDir, carmenArchiveDir string, recoveredBlock idx.Block) error {
func healLiveFromArchive(ctx context.Context, carmenLiveDir, carmenArchiveDir string, recoveredBlock idx.BlockID) error {
if err := os.RemoveAll(carmenLiveDir); err != nil {
return fmt.Errorf("failed to remove broken live state: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sonictool/chain/export_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
// always print out progress. This avoids the user wondering what's going on.
const statsReportLimit = 8 * time.Second

func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, from, to idx.Epoch) (err error) {
func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, from, to idx.EpochID) (err error) {
chaindataDir := filepath.Join(gdbParams.DataDir, "chaindata")
dbs, err := db.MakeDbProducer(chaindataDir, cachescale.Identity)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/sonictool/chain/import_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func importEventsFile(srv *gossip.Service, fn string) error {
batch := make(inter.EventPayloads, 0, 8*1024)
batchSize := 0
maxBatchSize := 8 * 1024 * 1024
epoch := idx.Epoch(0)
epoch := idx.EpochID(0)
txs := 0
events := 0

Expand Down
2 changes: 1 addition & 1 deletion cmd/sonictool/check/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func checkArchiveBlockRoots(dataDir string, cacheRatio cachescale.Func) error {

invalidBlocks := 0
lastBlockIdx := gdb.GetLatestBlockIndex()
for i := idx.Block(1); i <= lastBlockIdx; i++ {
for i := idx.BlockID(1); i <= lastBlockIdx; i++ {
block := gdb.GetBlock(i)
if block == nil {
return fmt.Errorf("verification failed - unable to get block %d from gdb", i)
Expand Down
14 changes: 7 additions & 7 deletions cmd/sonictool/db/heal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"
)

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

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

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

// getLastEpochWithState finds the last closed epoch with the state available
func getLastEpochWithState(gdb *gossip.Store, lastCarmenBlock idx.Block) (epochIdx idx.Epoch, blockState *iblockproc.BlockState, epochState *iblockproc.EpochState) {
func getLastEpochWithState(gdb *gossip.Store, lastCarmenBlock idx.BlockID) (epochIdx idx.EpochID, blockState *iblockproc.BlockState, epochState *iblockproc.EpochState) {
currentEpoch := gdb.GetEpoch()
epochsToTry := idx.Epoch(10000)
endEpoch := idx.Epoch(1)
epochsToTry := idx.EpochID(10000)
endEpoch := idx.EpochID(1)
if currentEpoch > epochsToTry {
endEpoch = currentEpoch - epochsToTry
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/sonictool/genesis/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func ExportGenesis(ctx context.Context, gdb *gossip.Store, includeArchive bool,
return nil
}

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

func exportBlocksSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter, to idx.Block, maxBlocks int64) error {
func exportBlocksSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter, to idx.BlockID, maxBlocks int64) error {
toBlock := int64(to)
fromBlock := int64(0)
if maxBlocks != 0 && toBlock > 1+maxBlocks {
fromBlock = toBlock - maxBlocks
}
log.Info("Exporting blocks", "from", fromBlock, "to", toBlock)
for i := toBlock; i >= fromBlock; i-- {
i := idx.Block(i)
i := idx.BlockID(i)
br := gdb.GetFullBlockRecord(i)
if br == nil {
return fmt.Errorf("the block record for block %d is missing in gdb", i)
Expand Down Expand Up @@ -177,7 +177,7 @@ func exportFwaSection(ctx context.Context, gdb *gossip.Store, writer *unitWriter
return nil
}

func getEpochBlock(epoch idx.Epoch, store *gossip.Store) idx.Block {
func getEpochBlock(epoch idx.EpochID, store *gossip.Store) idx.BlockID {
bs, _ := store.GetHistoryBlockEpochState(epoch)
if bs == nil {
return 0
Expand Down
2 changes: 1 addition & 1 deletion cmd/sonictool/genesis/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ImportGenesisStore(params ImportParams) error {
if err != nil {
return err
}
cGetEpochDB := func(epoch idx.Epoch) kvdb.Store {
cGetEpochDB := func(epoch idx.EpochID) kvdb.Store {
db, err := dbs.OpenDB(fmt.Sprintf("lachesis-%d", epoch))
if err != nil {
panic(fmt.Errorf("failed to open epoch db: %w", err))
Expand Down
4 changes: 2 additions & 2 deletions config/make_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func MakeNode(ctx *cli.Context, cfg *Config) (*node.Node, *gossip.Service, func(
}
return evmcore.NewTxPool(cfg.TxPool, reader.Config(), reader)
}
haltCheck := func(oldEpoch, newEpoch idx.Epoch, age time.Time) bool {
haltCheck := func(oldEpoch, newEpoch idx.EpochID, age time.Time) bool {
stop := ctx.GlobalIsSet(flags.ExitWhenAgeFlag.Name) && ctx.GlobalDuration(flags.ExitWhenAgeFlag.Name) >= time.Since(age)
stop = stop || ctx.GlobalIsSet(flags.ExitWhenEpochFlag.Name) && idx.Epoch(ctx.GlobalUint64(flags.ExitWhenEpochFlag.Name)) <= newEpoch
stop = stop || ctx.GlobalIsSet(flags.ExitWhenEpochFlag.Name) && idx.EpochID(ctx.GlobalUint64(flags.ExitWhenEpochFlag.Name)) <= newEpoch
if stop {
go func() {
// do it in a separate thread to avoid deadlock
Expand Down
4 changes: 2 additions & 2 deletions ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexO
return nil, err
}
oldest := last
if oldest > idx.Block(blockCount) {
oldest -= idx.Block(blockCount - 1)
if oldest > idx.BlockID(blockCount) {
oldest -= idx.BlockID(blockCount - 1)
} else {
oldest = 0
}
Expand Down
14 changes: 7 additions & 7 deletions ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import (

// PeerProgress is synchronization status of a peer
type PeerProgress struct {
CurrentEpoch idx.Epoch
CurrentBlock idx.Block
CurrentEpoch idx.EpochID
CurrentBlock idx.BlockID
CurrentBlockHash hash.Event
CurrentBlockTime inter.Timestamp
HighestBlock idx.Block
HighestEpoch idx.Epoch
HighestBlock idx.BlockID
HighestEpoch idx.EpochID
}

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

// Lachesis aBFT API
GetEpochBlockState(ctx context.Context, epoch rpc.BlockNumber) (*iblockproc.BlockState, *iblockproc.EpochState, error)
GetDowntime(ctx context.Context, vid idx.ValidatorID) (idx.Block, inter.Timestamp, error)
GetDowntime(ctx context.Context, vid idx.ValidatorID) (idx.BlockID, inter.Timestamp, error)
GetUptime(ctx context.Context, vid idx.ValidatorID) (*big.Int, error)
GetOriginatedFee(ctx context.Context, vid idx.ValidatorID) (*big.Int, error)
}
Expand Down
12 changes: 6 additions & 6 deletions ethapi/mock_backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions eventcheck/epochcheck/epoch_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
// Reader returns currents epoch and its validators group.
type Reader interface {
base.Reader
GetEpochRules() (opera.Rules, idx.Epoch)
GetEpochRules() (opera.Rules, idx.EpochID)
}

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

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

Expand Down Expand Up @@ -110,7 +110,7 @@ func (v *Checker) Validate(e inter.EventPayloadI) error {
if e.Epoch() != epoch {
return base.ErrNotRelevant
}
if idx.Event(len(e.Parents())) > rules.Dag.MaxParents {
if idx.EventID(len(e.Parents())) > rules.Dag.MaxParents {
return ErrTooManyParents
}
if uint32(len(e.Extra())) > rules.Dag.MaxExtraData {
Expand Down
2 changes: 1 addition & 1 deletion eventcheck/gaspowercheck/gas_power_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ValidatorState struct {

// ValidationContext for gaspower checking
type ValidationContext struct {
Epoch idx.Epoch
Epoch idx.EpochID
Configs [inter.GasPowerConfigs]Config
EpochStart inter.Timestamp
Validators *ltypes.Validators
Expand Down
8 changes: 4 additions & 4 deletions eventcheck/heavycheck/heavy_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var (

// Reader is accessed by the validator to get the current state.
type Reader interface {
GetEpochPubKeys() (map[idx.ValidatorID]validatorpk.PubKey, idx.Epoch)
GetEpochPubKeysOf(idx.Epoch) map[idx.ValidatorID]validatorpk.PubKey
GetEpochBlockStart(idx.Epoch) idx.Block
GetEpochPubKeys() (map[idx.ValidatorID]validatorpk.PubKey, idx.EpochID)
GetEpochPubKeysOf(idx.EpochID) map[idx.ValidatorID]validatorpk.PubKey
GetEpochBlockStart(idx.EpochID) idx.BlockID
}

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

func (v *Checker) ValidateEventLocator(e inter.SignedEventLocator, authEpoch idx.Epoch, authErr error, checkPayload func() bool) error {
func (v *Checker) ValidateEventLocator(e inter.SignedEventLocator, authEpoch idx.EpochID, authErr error, checkPayload func() bool) error {
pubkeys := v.reader.GetEpochPubKeysOf(authEpoch)
if len(pubkeys) == 0 {
return authErr
Expand Down
2 changes: 1 addition & 1 deletion evmcore/dummy_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type (

PrevRandao common.Hash // == mixHash/mixDigest

Epoch idx.Epoch
Epoch idx.EpochID
}

EvmBlock struct {
Expand Down
Loading

0 comments on commit da53523

Please sign in to comment.