Skip to content

Commit

Permalink
Merge branch 'enrfilter' into x1-txtracing-enrfilter
Browse files Browse the repository at this point in the history
  • Loading branch information
nibty committed Apr 8, 2024
2 parents a4b4a9b + 2a85607 commit 01292e6
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ testnet.g
dist/
/docker/networksimulator/docker-compose.yaml
/docker/networksimulator/prometheus/prometheus.yml
/docker/networksimulator/.env
12 changes: 0 additions & 12 deletions .run/testnet.run.xml

This file was deleted.

1 change: 1 addition & 0 deletions cmd/opera/launcher/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
"enode://5d1a3b86c8ee297142fb916db77785cc679d4ed10f51cca84c9ee9442d66280a90378d9ca364620bd8cebec0aafb2cf22cd033905afe2028c22b804a2e18d981@bootnode0.x1-testnet.xen.network:5050",
"enode://703e4f01760a1f432d5e5e9a8a9c86b5dca301563bc9559f8c991de052e438d8072b2e789f7722762ea44c5c06ed87428a25606f278a128d7a39bd5996be9536@bootnode1.x1-testnet.xen.network:5050",
"enode://873de92942769e57c2360dd3198af2fda9602a9826b1f1a6d36326b6a75c9178c4f13f910c9e715a5ca6344aa62452930fcee18636ab0a95f269dded52f45960@bootnode2.x1-testnet.xen.network:5050",
"enode://125e59370d9c7f5a195e2b99da9bb4172c8ac7dde74bb47a5b97fdfbeb3e876ee64289fd05b96b2b24006e00c4a6ad990ae159008f006f809966636797ab0054@bootnode3.x1-testnet.xen.network:5050",
},
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/opera/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package main

import (
"fmt"
"github.com/ethereum/go-ethereum/log"
"os"

"github.com/Fantom-foundation/go-opera/cmd/opera/launcher"
)

func main() {
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stdout, log.TerminalFormat(true))))

if err := launcher.Launch(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions docker/networksimulator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
jinja2
web3
dotenv
4 changes: 2 additions & 2 deletions docker/networksimulator/txblaster.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def generate_accounts(self, num_accounts: int, menmonic: str, fund_value: int):
tx_hashes.append(tx_hash)
accounts.append(acc)
for tx_hash in tx_hashes:
self.web3.eth.wait_for_transaction_receipt(tx_hash)
self.web3.eth.wait_for_transaction_receipt(tx_hash, timeout=60000)
return accounts

def run_transactions(self, private_key, args):
Expand Down Expand Up @@ -104,7 +104,7 @@ def run_transactions(self, private_key, args):
continue

start_time = time()
self.web3.eth.wait_for_transaction_receipt(tx_hash)
self.web3.eth.wait_for_transaction_receipt(tx_hash, timeout=60000)
logging.info("tx confirmed tx_receipt=%s time=%f", tx_hash.hex(), time() - start_time)

def sig_int(self, signum, frame):
Expand Down
7 changes: 7 additions & 0 deletions ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
"sync"
"math/rand"
"os"
"time"

"github.com/Fantom-foundation/lachesis-base/hash"
Expand Down Expand Up @@ -2438,6 +2439,12 @@ func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
return api.b.ChainDb().Stat(property)
}

// Verbosity sets the log level of the node.
func (api *PrivateDebugAPI) Verbosity(level int) {
log.Info("Setting log level", "level", log.Lvl(level).String())
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(level), log.StreamHandler(os.Stdout, log.TerminalFormat(true))))
}

// ChaindbCompact flattens the entire key-value database into a single level,
// removing all unused slots and merging all keys.
func (api *PrivateDebugAPI) ChaindbCompact() error {
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/faircrypto/go-ethereum v1.1.4-rc1-6
require github.com/panjf2000/ants/v2 v2.4.5 // indirect

replace github.com/ethereum/go-ethereum => github.com/faircrypto/go-ethereum v1.10.8-ftm-rc9.0.20240408233151-381ed183bc52

//replace github.com/ethereum/go-ethereum => ./go-ethereum

replace github.com/Fantom-foundation/lachesis-base => github.com/faircrypto/lachesis-base v0.0.0-20230817040848-1326ba9aa59b

Expand Down
7 changes: 5 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/evalphobia/logrus_sentry v0.8.2 h1:dotxHq+YLZsT1Bb45bB5UQbfCh3gM/nFFetyN46VoDQ=
github.com/evalphobia/logrus_sentry v0.8.2/go.mod h1:pKcp+vriitUqu9KiWj/VRFbRfFNUwz95/UkgG8a6MNc=
github.com/faircrypto/go-ethereum v1.1.4-rc1-6 h1:74OcB2uM0q7sCyW2k52vvP4ALdJjSYWvEVpE+poCOGs=
github.com/faircrypto/go-ethereum v1.1.4-rc1-6/go.mod h1:ah5rnRobPJSTUKXIETbrkyrrEhWPTUPfmF1gPPNr0Tg=
github.com/faircrypto/go-ethereum v1.10.8-ftm-rc9.0.20240408233151-381ed183bc52 h1:tDi9ifPQRjBAhnMPei0N4GGd3yS/6mB+2n6HrWLhVEU=
github.com/faircrypto/go-ethereum v1.10.8-ftm-rc9.0.20240408233151-381ed183bc52/go.mod h1:738t3sZkf8FVTNT/34/PppH8Bn60QinNrWrzh9tJQqE=
github.com/faircrypto/lachesis-base v0.0.0-20230817040848-1326ba9aa59b h1:mEofwrV6bMlbuneVS8tnZmNZut7WY2YH++2GI7DxzHg=
github.com/faircrypto/lachesis-base v0.0.0-20230817040848-1326ba9aa59b/go.mod h1:Ogv5etzSmM2rQ4eN3OfmyitwWaaPjd4EIDiW/NAbYGk=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
Expand Down Expand Up @@ -514,6 +514,8 @@ github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/panjf2000/ants/v2 v2.4.5 h1:kcGvjXB7ea0MrzzszpnlVFthhYKoFxLi75nRbsq01HY=
github.com/panjf2000/ants/v2 v2.4.5/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
Expand Down Expand Up @@ -1068,6 +1070,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
10 changes: 10 additions & 0 deletions gossip/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gossip
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/forkid"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rlp"

Expand Down Expand Up @@ -59,6 +60,15 @@ func StartENRUpdater(svc *Service, ln *enode.LocalNode) {
}()
}

func StartENRFilter(svc *Service, p2p *p2p.Server) {
chainConfig := svc.store.GetEvmChainConfig()
gh := common.Hash(*svc.store.GetGenesisID())
forkFilter := forkid.NewOperaFilter(chainConfig, gh, func() uint64 {
return uint64(svc.store.GetLatestBlockIndex())
})
p2p.SetFilter(forkFilter)
}

// currentENREntry constructs an `eth` ENR entry based on the current state of the chain.
func currentENREntry(svc *Service) *enrEntry {
genesisHash := *svc.store.GetGenesisID()
Expand Down
12 changes: 12 additions & 0 deletions gossip/emitter/control.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emitter

import (
"github.com/ethereum/go-ethereum/metrics"
"time"

"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
Expand All @@ -11,6 +12,11 @@ import (
"github.com/Fantom-foundation/go-opera/inter"
)

var (
allowedToEmitCount = metrics.GetOrRegisterGauge("opera/control/allowedToEmit", nil)
notAllowedToEmitCount = metrics.GetOrRegisterGauge("opera/control/notAllowedToEmit", nil)
)

func scalarUpdMetric(diff idx.Event, weight pos.Weight, totalWeight pos.Weight) ancestor.Metric {
return ancestor.Metric(scalarUpdMetricF(uint64(diff)*piecefunc.DecimalUnit)) * ancestor.Metric(weight) / ancestor.Metric(totalWeight)
}
Expand Down Expand Up @@ -73,6 +79,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
"power", e.GasPowerLeft().String(),
"selfParentPower", selfParent.GasPowerLeft().String(),
"stake%", 100*float64(em.validators.Get(e.Creator()))/float64(em.validators.TotalWeight()))
notAllowedToEmitCount.Inc(1)
return false
}
}
Expand All @@ -87,6 +94,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
if passedTime >= em.intervals.Max ||
passedBlocks >= maxBlocks*4/5 && metric >= piecefunc.DecimalUnit/2 ||
passedBlocks >= maxBlocks {
allowedToEmitCount.Inc(1)
return true
}
}
Expand All @@ -109,6 +117,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
if passedTime < em.intervals.Max &&
em.idle() &&
!eTxs {
notAllowedToEmitCount.Inc(1)
return false
}
}
Expand All @@ -119,15 +128,18 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
}
if adjustedPassedTime < em.intervals.Min &&
!em.idle() {
notAllowedToEmitCount.Inc(1)
return false
}
if adjustedPassedIdleTime < em.intervals.Confirming &&
!em.idle() &&
!eTxs {
notAllowedToEmitCount.Inc(1)
return false
}
}

allowedToEmitCount.Inc(1)
return true
}

Expand Down
13 changes: 11 additions & 2 deletions gossip/emitter/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const (
)

var eventCounter = metrics.GetOrRegisterCounter("opera/events", nil)
var callCreatedCounter = metrics.GetOrRegisterCounter("opera/events/callCreated", nil)
var callEmitCounter = metrics.GetOrRegisterCounter("opera/events/callEmit", nil)
var worldBusyGauge = metrics.GetOrRegisterGauge("opera/events/worldBusy", nil)

type Emitter struct {
config Config
Expand Down Expand Up @@ -189,7 +192,10 @@ func (em *Emitter) tick() {
em.busyRate.Mark(1)
}
if em.world.IsBusy() {
worldBusyGauge.Update(1)
return
} else {
worldBusyGauge.Update(0)
}

em.recheckChallenges()
Expand Down Expand Up @@ -233,6 +239,8 @@ func (em *Emitter) EmitEvent() (*inter.EventPayload, error) {
// short circuit if not a validator
return nil, nil
}
callEmitCounter.Inc(1)

sortedTxs := em.getSortedTxs()

if em.world.IsBusy() {
Expand Down Expand Up @@ -295,6 +303,7 @@ func (em *Emitter) createEvent(sortedTxs *types.TransactionsByPriceAndNonce) (*i
if !em.isValidator() {
return nil, nil
}
callCreatedCounter.Inc(1)

if synced := em.logSyncStatus(em.isSyncedToEmit()); !synced {
// I'm reindexing my old events, so don't create events until connect all the existing self-events
Expand Down Expand Up @@ -361,8 +370,8 @@ func (em *Emitter) createEvent(sortedTxs *types.TransactionsByPriceAndNonce) (*i
mutEvent.SetCreationTime(inter.MaxTimestamp(inter.Timestamp(time.Now().UnixNano()), selfParentTime+1))

// add LLR votes
em.addLlrEpochVote(mutEvent)
em.addLlrBlockVotes(mutEvent)
//em.addLlrEpochVote(mutEvent)
//em.addLlrBlockVotes(mutEvent)

// node version
if mutEvent.Seq() <= 1 && len(em.config.VersionToPublish) > 0 {
Expand Down
42 changes: 40 additions & 2 deletions gossip/emitter/txs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package emitter

import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"time"

"github.com/Fantom-foundation/lachesis-base/common/bigendian"
Expand All @@ -24,6 +26,19 @@ const (
TxTurnNonces = 32
)

var (
outOfGasPowerCounter = metrics.GetOrRegisterCounter("opera/txs/outOfGasPower", nil)
conflictedOriginatedCounter = metrics.GetOrRegisterCounter("opera/txs/conflictedOriginated", nil)
isMyTurnCounter = metrics.GetOrRegisterCounter("opera/txs/isMyTurn", nil)
isNotMyTurnCounter = metrics.GetOrRegisterCounter("opera/txs/isNotMyTurn", nil)
outdatedCounter = metrics.GetOrRegisterCounter("opera/txs/outdated", nil)
invalidTxCounter = metrics.GetOrRegisterCounter("opera/txs/invalidTxCounter", nil)

gasPowerUsedGauge = metrics.GetOrRegisterGauge("opera/txs/gasPowerUsed", nil)
gasPowerLeftShortGauge = metrics.GetOrRegisterGauge("opera/txs/gasPowerLeftShort", nil)
gasPowerLeftLongGauge = metrics.GetOrRegisterGauge("opera/txs/gasPowerLeftLong", nil)
)

func max64(a, b uint64) uint64 {
if a > b {
return a
Expand Down Expand Up @@ -123,6 +138,10 @@ func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, account

roundsHash := hash.Of(sender.Bytes(), bigendian.Uint64ToBytes(accountNonce/TxTurnNonces), epoch.Bytes())
rounds := utils.WeightedPermutation(roundIndex+1, validators.SortedWeights(), roundsHash)

chosen := validators.GetID(idx.Validator(rounds[roundIndex]))
log.Debug("tx turn", "roundIndex", roundIndex, "rounds", rounds, "chosen", chosen, "me", me, "txTime", txTime, "now", now, "txHash", txHash, "sender", sender, "accountNonce", accountNonce, "epoch", epoch)

return validators.GetID(idx.Validator(rounds[roundIndex])) == me
}

Expand All @@ -138,11 +157,14 @@ func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.Transactio
sender, _ := types.Sender(em.world.TxSigner, tx)
// check transaction epoch rules
if epochcheck.CheckTxs(types.Transactions{tx}, rules) != nil {
invalidTxCounter.Inc(1)
sorted.Pop()
continue
}
// check there's enough gas power to originate the transaction
if tx.Gas() >= e.GasPowerLeft().Min() || e.GasPowerUsed()+tx.Gas() >= maxGasUsed {
log.Debug("not enough gas power to originate the transaction")
outOfGasPowerCounter.Inc(1)
if params.TxGas >= e.GasPowerLeft().Min() || e.GasPowerUsed()+params.TxGas >= maxGasUsed {
// stop if cannot originate even an empty transaction
break
Expand All @@ -152,22 +174,38 @@ func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.Transactio
}
// check not conflicted with already originated txs (in any connected event)
if em.originatedTxs.TotalOf(sender) != 0 {
conflictedOriginatedCounter.Inc(1)
log.Debug("conflicted with already originated txs")
sorted.Pop()
continue
}
// my turn, i.e. try to not include the same tx simultaneously by different validators
if !em.isMyTxTurn(tx.Hash(), sender, tx.Nonce(), time.Now(), em.validators, e.Creator(), em.epoch) {
sorted.Pop()
isNotMyTurnCounter.Inc(1)
continue
} else {
isMyTurnCounter.Inc(1)
}

// check transaction is not outdated
if !em.world.TxPool.Has(tx.Hash()) {
outdatedCounter.Inc(1)
sorted.Pop()
log.Debug("transaction is outdated")
continue
}
gasPowerUsed := e.GasPowerUsed() + tx.Gas()
gasPowerLeft := e.GasPowerLeft().Sub(tx.Gas())
log.Debug("gas power", "used", gasPowerUsed, "left", gasPowerLeft)

gasPowerUsedGauge.Update(int64(gasPowerUsed))
gasPowerLeftShortGauge.Update(int64(gasPowerLeft.Gas[inter.ShortTermGas]))
gasPowerLeftLongGauge.Update(int64(gasPowerLeft.Gas[inter.LongTermGas]))

// add
e.SetGasPowerUsed(e.GasPowerUsed() + tx.Gas())
e.SetGasPowerLeft(e.GasPowerLeft().Sub(tx.Gas()))
e.SetGasPowerUsed(gasPowerUsed)
e.SetGasPowerLeft(gasPowerLeft)
e.SetTxs(append(e.Txs(), tx))
sorted.Shift()
}
Expand Down
11 changes: 11 additions & 0 deletions gossip/emitter/validators.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package emitter

import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"time"

"github.com/Fantom-foundation/lachesis-base/inter/idx"
Expand All @@ -12,6 +14,10 @@ const (
validatorChallenge = 4 * time.Second
)

var (
offlineValidatorsGauge = metrics.GetOrRegisterGauge("opera/validators/offline", nil)
)

func (em *Emitter) recountConfirmingIntervals(validators *pos.Validators) {
// validators with lower stake should emit fewer events to reduce network load
// confirmingEmitInterval = piecefunc(totalStakeBeforeMe / totalStake) * MinEmitInterval
Expand Down Expand Up @@ -55,6 +61,7 @@ func (em *Emitter) recheckChallenges() {
recount := false
for vid, challengeDeadline := range em.challenges {
if now.After(challengeDeadline) {
log.Debug("validator is offline", "validator", vid)
em.offlineValidators[vid] = true
recount = true
}
Expand All @@ -63,4 +70,8 @@ func (em *Emitter) recheckChallenges() {
em.recountConfirmingIntervals(em.validators)
}
em.prevRecheckedChallenges = now

numOfOfflineVals := int64(len(em.offlineValidators))
log.Debug("offline validators", "num", numOfOfflineVals)
offlineValidatorsGauge.Update(numOfOfflineVals)
}
Loading

0 comments on commit 01292e6

Please sign in to comment.