Skip to content

Commit

Permalink
Refactor dag and pos types
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Scholz committed Dec 4, 2024
1 parent 397f02b commit 6d66ff5
Show file tree
Hide file tree
Showing 49 changed files with 117 additions and 124 deletions.
2 changes: 1 addition & 1 deletion cmd/sonicd/app/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
ipcAPIs = "abft:1.0 admin:1.0 dag:1.0 debug:1.0 ftm:1.0 net:1.0 personal:1.0 rpc:1.0 trace:1.0 txpool:1.0 web3:1.0"
ipcAPIs = "abft:1.0 admin:1.0 dag:1.0 debug:1.0 ftm:1.0 net:1.0 personal:1.0 rpc:1.0 trace:1.0 txpool:1.0 web3:1.0"
)

func TestFakeNetFlag_NonValidator(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/sonicd/metrics/disksize.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func SetDataDir(datadir string) {

func measureDbDir(name, datadir string) {
var (
gauge = metrics.GetOrRegisterGauge(name, nil)
gauge = metrics.GetOrRegisterGauge(name, nil)
rescan = len(datadir) > 0 && datadir != "inmemory"
)
for rescan {
Expand Down
6 changes: 3 additions & 3 deletions cmd/sonictool/genesis/allowed.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ var (
Name: "Mainnet-279701 with Carmen live and archive state",
Header: mainnetHeader,
Hashes: genesis.Hashes{
genesisstore.EpochsSection(0): hash.HexToHash("0x6a685f5b446eb17cc69047ddd230c0ccc0c820d4ba05bfdd30aa6176b40618da"),
genesisstore.BlocksSection(0): hash.HexToHash("0xdf6ed841b928fad8632b7e532f0b989d93e26b8332fe8429504822df6d44a642"),
genesisstore.FwsLiveSection(0): hash.HexToHash("0x702c987a8e799d7550db6a3fc9a571cbaeac7a00d7bb984a00374a27bd25d908"),
genesisstore.EpochsSection(0): hash.HexToHash("0x6a685f5b446eb17cc69047ddd230c0ccc0c820d4ba05bfdd30aa6176b40618da"),
genesisstore.BlocksSection(0): hash.HexToHash("0xdf6ed841b928fad8632b7e532f0b989d93e26b8332fe8429504822df6d44a642"),
genesisstore.FwsLiveSection(0): hash.HexToHash("0x702c987a8e799d7550db6a3fc9a571cbaeac7a00d7bb984a00374a27bd25d908"),
genesisstore.FwsArchiveSection(0): hash.HexToHash("0xf445000720ef2969aa0fb4db6f5542452b5ea83fbf54dc1dcbe9202af0feafd8"),
},
},
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var NodeDefaultConfig = node.Config{
GraphQLVirtualHosts: []string{"localhost"},
P2P: p2p.Config{
NoDiscovery: false, // enable discovery by default
DiscoveryV4: false, // disable discovery v4 by default
DiscoveryV4: false, // disable discovery v4 by default
DiscoveryV5: true, // enable discovery v5 by default
ListenAddr: fmt.Sprintf(":%d", flags.ListenPortFlag.Value),
MaxPeers: 50,
Expand Down
2 changes: 0 additions & 2 deletions config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/Fantom-foundation/go-opera/inter/validatorpk"
)



// setValidatorID retrieves the validator ID either from the directly specified
// command line flags or from the keystore if CLI indexed.
func setValidator(ctx *cli.Context, cfg *emitter.Config) error {
Expand Down
8 changes: 4 additions & 4 deletions eventcheck/gaspowercheck/gas_power_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/Fantom-foundation/lachesis-base/eventcheck/epochcheck"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"

"github.com/Fantom-foundation/go-opera/inter"
"github.com/Fantom-foundation/go-opera/inter/iblockproc"
Expand All @@ -29,7 +29,7 @@ type ValidationContext struct {
Epoch idx.Epoch
Configs [inter.GasPowerConfigs]Config
EpochStart inter.Timestamp
Validators *pos.Validators
Validators *ltypes.Validators
ValidatorStates []ValidatorState
}

Expand Down Expand Up @@ -106,7 +106,7 @@ func calcGasPower(e inter.EventI, selfParent inter.EventI, ctx *ValidationContex
return CalcValidatorGasPower(e, e.MedianTime(), prevTime, prevGasPowerLeft, ctx.Validators, config)
}

func CalcValidatorGasPower(e inter.EventI, eTime, prevTime inter.Timestamp, prevGasPowerLeft uint64, validators *pos.Validators, config Config) uint64 {
func CalcValidatorGasPower(e inter.EventI, eTime, prevTime inter.Timestamp, prevGasPowerLeft uint64, validators *ltypes.Validators, config Config) uint64 {
gasPowerPerSec, maxGasPower, startup := CalcValidatorGasPowerPerSec(e.Creator(), validators, config)

if e.SelfParent() == nil {
Expand All @@ -133,7 +133,7 @@ func CalcValidatorGasPower(e inter.EventI, eTime, prevTime inter.Timestamp, prev

func CalcValidatorGasPowerPerSec(
validator idx.ValidatorID,
validators *pos.Validators,
validators *ltypes.Validators,
config Config,
) (
perSec uint64,
Expand Down
4 changes: 2 additions & 2 deletions gossip/blockproc/sealmodule/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"math/big"

"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/lachesis"
"github.com/Fantom-foundation/lachesis-base/ltypes"

"github.com/Fantom-foundation/go-opera/gossip/blockproc"
"github.com/Fantom-foundation/go-opera/inter/iblockproc"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (p *OperaEpochsSealer) Update(bs iblockproc.BlockState, es iblockproc.Epoch
func (s *OperaEpochsSealer) SealEpoch() (iblockproc.BlockState, iblockproc.EpochState) {
// Select new validators
oldValidators := s.es.Validators
builder := pos.NewBigBuilder()
builder := ltypes.NewBigBuilder()
for v, profile := range s.bs.NextValidatorProfiles {
builder.Set(v, profile.Weight)
}
Expand Down
7 changes: 3 additions & 4 deletions gossip/c_block_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (
"github.com/Fantom-foundation/go-opera/utils/signers/gsignercache"

"github.com/Fantom-foundation/lachesis-base/hash"
ltypes "github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/lachesis"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/utils/workers"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -90,7 +89,7 @@ func consensusCallbackBeginBlockFn(
// ignore block processing during bootstrapping
return lachesis.BlockCallbacks{
ApplyEvent: func(ltypes.Event) {},
EndBlock: func() *pos.Validators {
EndBlock: func() *ltypes.Validators {
return nil
},
}
Expand Down Expand Up @@ -140,7 +139,7 @@ func consensusCallbackBeginBlockFn(
}
confirmedEventsMeter.Mark(1)
},
EndBlock: func() (newValidators *pos.Validators) {
EndBlock: func() (newValidators *ltypes.Validators) {
if atroposTime <= bs.LastBlock.Time {
atroposTime = bs.LastBlock.Time + 1
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/c_event_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/Fantom-foundation/lachesis-base/gossip/dagprocessor"
"github.com/Fantom-foundation/lachesis-base/hash"
ltypes "github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
ltypes "github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

Expand Down
4 changes: 2 additions & 2 deletions gossip/checker_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sync/atomic"

"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"

"github.com/Fantom-foundation/go-opera/eventcheck/gaspowercheck"
"github.com/Fantom-foundation/go-opera/inter"
Expand All @@ -23,7 +23,7 @@ func (r *GasPowerCheckReader) GetValidationContext() *gaspowercheck.ValidationCo
}

// NewGasPowerContext reads current validation context for gaspowercheck
func NewGasPowerContext(s *Store, validators *pos.Validators, epoch idx.Epoch, cfg opera.EconomyRules) *gaspowercheck.ValidationContext {
func NewGasPowerContext(s *Store, validators *ltypes.Validators, epoch idx.Epoch, cfg opera.EconomyRules) *gaspowercheck.ValidationContext {
// engineMu is locked here

short := cfg.ShortGasPower
Expand Down
2 changes: 1 addition & 1 deletion gossip/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

"github.com/Fantom-foundation/lachesis-base/abft"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down
2 changes: 1 addition & 1 deletion gossip/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/Fantom-foundation/lachesis-base/gossip/dagprocessor"
"github.com/Fantom-foundation/lachesis-base/gossip/itemsfetcher"
ltypes "github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
ltypes "github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
"github.com/syndtr/goleveldb/leveldb/opt"

Expand Down
6 changes: 3 additions & 3 deletions gossip/emitter/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (

"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/utils/piecefunc"

"github.com/Fantom-foundation/go-opera/inter"
"github.com/Fantom-foundation/go-opera/opera"
)

func scalarUpdMetric(diff idx.Event, weight pos.Weight, totalWeight pos.Weight) ancestor.Metric {
func scalarUpdMetric(diff idx.Event, weight ltypes.Weight, totalWeight ltypes.Weight) ancestor.Metric {
return ancestor.Metric(scalarUpdMetricF(uint64(diff)*piecefunc.DecimalUnit)) * ancestor.Metric(weight) / ancestor.Metric(totalWeight)
}

func updMetric(median, cur, upd idx.Event, validatorIdx idx.Validator, validators *pos.Validators) ancestor.Metric {
func updMetric(median, cur, upd idx.Event, validatorIdx idx.Validator, validators *ltypes.Validators) ancestor.Metric {
if upd <= median || upd <= cur {
return 0
}
Expand Down
4 changes: 2 additions & 2 deletions gossip/emitter/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/utils/piecefunc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/txpool"
Expand Down Expand Up @@ -67,7 +67,7 @@ type Emitter struct {

// note: track validators and epoch internally to avoid referring to
// validators of a future epoch inside OnEventConnected of last epoch event
validators *pos.Validators
validators *ltypes.Validators
epoch idx.Epoch

// challenges is deadlines when each validator should emit an event
Expand Down
6 changes: 3 additions & 3 deletions gossip/emitter/emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/golang/mock/gomock"
Expand All @@ -26,9 +26,9 @@ import (
func TestEmitter(t *testing.T) {
cfg := DefaultConfig()
gValidators := makefakegenesis.GetFakeValidators(3)
vv := pos.NewBuilder()
vv := ltypes.NewBuilder()
for _, v := range gValidators {
vv.Set(v.ID, pos.Weight(1))
vv.Set(v.ID, ltypes.Weight(1))
}
validators := vv.Build()
cfg.Validator.ID = gValidators[0].ID
Expand Down
4 changes: 2 additions & 2 deletions gossip/emitter/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

Expand All @@ -18,7 +18,7 @@ import (
)

// OnNewEpoch should be called after each epoch change, and on startup
func (em *Emitter) OnNewEpoch(newValidators *pos.Validators, newEpoch idx.Epoch) {
func (em *Emitter) OnNewEpoch(newValidators *ltypes.Validators, newEpoch idx.Epoch) {
em.maxParents = em.config.MaxParents
rules := em.world.GetRules()
if em.maxParents == 0 {
Expand Down
8 changes: 4 additions & 4 deletions gossip/emitter/mock/world.go

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

6 changes: 3 additions & 3 deletions gossip/emitter/parents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/kvdb/memorydb"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/golang/mock/gomock"
)

Expand Down Expand Up @@ -54,9 +54,9 @@ func TestChooseParents_NonGenesisEventMustHaveOneSelfParent(t *testing.T) {
validatorId := idx.ValidatorID(1)

validatorIndex := vecmt.NewIndex(nil, vecmt.LiteConfig())
validatorIndex.Reset(pos.ArrayToValidators(
validatorIndex.Reset(ltypes.ArrayToValidators(
[]idx.ValidatorID{1, 2},
[]pos.Weight{1, 1},
[]ltypes.Weight{1, 1},
), memorydb.New(), nil)

selfParentHash := hash.Event{1}
Expand Down
4 changes: 2 additions & 2 deletions gossip/emitter/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/Fantom-foundation/lachesis-base/common/bigendian"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -112,7 +112,7 @@ func getTxRoundIndex(now, txTime time.Time, validatorsNum idx.Validator) int {
}

// safe for concurrent use
func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, accountNonce uint64, now time.Time, validators *pos.Validators, me idx.ValidatorID, epoch idx.Epoch) bool {
func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, accountNonce uint64, now time.Time, validators *ltypes.Validators, me idx.ValidatorID, epoch idx.Epoch) bool {
txTime := txtime.Of(txHash)

roundIndex := getTxRoundIndex(now, txTime, validators.Len())
Expand Down
8 changes: 4 additions & 4 deletions gossip/emitter/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"time"

"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/Fantom-foundation/lachesis-base/utils/piecefunc"
)

const (
validatorChallenge = 4 * time.Second
)

func (em *Emitter) recountConfirmingIntervals(validators *pos.Validators) {
func (em *Emitter) recountConfirmingIntervals(validators *ltypes.Validators) {
// validators with lower stake should emit fewer events to reduce network load
// confirmingEmitInterval = piecefunc(totalStakeBeforeMe / totalStake) * MinEmitInterval
totalStakeBefore := pos.Weight(0)
totalStakeBefore := ltypes.Weight(0)
for i, stake := range validators.SortedWeights() {
vid := validators.GetID(idx.Validator(i))
// pos.Weight is uint32, so cast to uint64 to avoid an overflow
// ltypes.Weight is uint32, so cast to uint64 to avoid an overflow
stakeRatio := uint64(totalStakeBefore) * uint64(piecefunc.DecimalUnit) / uint64(validators.TotalWeight())
if !em.offlineValidators[vid] {
totalStakeBefore += stake
Expand Down
4 changes: 2 additions & 2 deletions gossip/emitter/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/inter/pos"
"github.com/Fantom-foundation/lachesis-base/ltypes"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

Expand Down Expand Up @@ -56,7 +56,7 @@ type (
// Reader is a callback for getting events from an external storage.
type Reader interface {
GetLatestBlockIndex() idx.Block
GetEpochValidators() (*pos.Validators, idx.Epoch)
GetEpochValidators() (*ltypes.Validators, idx.Epoch)
GetEvent(hash.Event) *inter.Event
GetEventPayload(hash.Event) *inter.EventPayload
GetLastEvent(epoch idx.Epoch, from idx.ValidatorID) *hash.Event
Expand Down
10 changes: 5 additions & 5 deletions gossip/evmstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type (
func DefaultStoreConfig(scale cachescale.Func) StoreConfig {
return StoreConfig{
Cache: StoreCacheConfig{
ReceiptsSize: scale.U(4 * opt.MiB),
ReceiptsBlocks: scale.I(4000),
TxPositions: scale.I(20000),
EvmBlocksNum: scale.I(5000),
EvmBlocksSize: scale.U(6 * opt.MiB),
ReceiptsSize: scale.U(4 * opt.MiB),
ReceiptsBlocks: scale.I(4000),
TxPositions: scale.I(20000),
EvmBlocksNum: scale.I(5000),
EvmBlocksSize: scale.U(6 * opt.MiB),
},
StateDb: carmen.Parameters{
Variant: "go-file",
Expand Down
Loading

0 comments on commit 6d66ff5

Please sign in to comment.