Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e4: added some metrics to code #7078

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
"runtime"
"time"

"github.com/VictoriaMetrics/metrics"
"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"

chain2 "github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/commitment"
libcommon "github.com/ledgerwatch/erigon-lib/common"
Expand All @@ -19,8 +23,6 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
libstate "github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"

"github.com/ledgerwatch/erigon/cmd/hack/tool/fromdb"
"github.com/ledgerwatch/erigon/cmd/state/exec3"
Expand Down Expand Up @@ -58,6 +60,11 @@ func init() {
var (
dirtySpaceThreshold = uint64(2 * 1024 * 1024 * 1024) /* threshold of dirty space in MDBX transaction that triggers a commit */
blockRootMismatchExpected bool

mxBlockExecutionTimer = metrics.GetOrCreateSummary("chain_execution_seconds")
mxTxProcessed = metrics.GetOrCreateCounter("domain_tx_processed")
mxBlockProcessed = metrics.GetOrCreateCounter("domain_block_processed")
mxRunningCommits = metrics.GetOrCreateCounter("domain_running_commits")
)

var stateDomains = &cobra.Command{
Expand Down Expand Up @@ -97,38 +104,12 @@ var stateDomains = &cobra.Command{
},
}

func ParseTrieVariant(s string) commitment.TrieVariant {
var trieVariant commitment.TrieVariant
switch s {
case "bin":
trieVariant = commitment.VariantBinPatriciaTrie
case "hex":
fallthrough
default:
trieVariant = commitment.VariantHexPatriciaTrie
}
return trieVariant
}

func ParseCommitmentMode(s string) libstate.CommitmentMode {
var mode libstate.CommitmentMode
switch s {
case "off":
mode = libstate.CommitmentModeDisabled
case "update":
mode = libstate.CommitmentModeUpdate
default:
mode = libstate.CommitmentModeDirect
}
return mode
}

func loopProcessDomains(chainDb, stateDb kv.RwDB, ctx context.Context) error {
trieVariant := ParseTrieVariant(commitmentTrie)
trieVariant := commitment.ParseTrieVariant(commitmentTrie)
if trieVariant != commitment.VariantHexPatriciaTrie {
blockRootMismatchExpected = true
}
mode := ParseCommitmentMode(commitmentMode)
mode := libstate.ParseCommitmentMode(commitmentMode)

engine, _, _, agg := newDomains(ctx, chainDb, mode, trieVariant)
defer agg.Close()
Expand All @@ -155,12 +136,13 @@ func loopProcessDomains(chainDb, stateDb kv.RwDB, ctx context.Context) error {
log.Info("Max txNum in files", "txn", latestTx)
}

aggWriter, aggReader := WrapAggregator(agg, stateTx)
proc := blockProcessor{
chainConfig: fromdb.ChainConfig(chainDb),
vmConfig: vm.Config{},
engine: engine,
reader: &ReaderWrapper4{ac: agg.MakeContext(), roTx: stateTx},
writer: &WriterWrapper4{w: agg},
reader: aggReader,
writer: aggWriter,
blockReader: getBlockReader(chainDb),
stateTx: stateTx,
stateDb: stateDb,
Expand Down Expand Up @@ -242,6 +224,8 @@ func (b *blockProcessor) commit(ctx context.Context) error {
return fmt.Errorf("commit failed due to invalid chainDb/rwTx")
}

mxRunningCommits.Inc()
defer mxRunningCommits.Dec()
var spaceDirty uint64
var err error
if spaceDirty, _, err = b.stateTx.(*kv2.MdbxTx).SpaceDirty(); err != nil {
Expand All @@ -263,10 +247,8 @@ func (b *blockProcessor) commit(ctx context.Context) error {
return err
}

b.reader.ac.Close()
b.agg.SetTx(b.stateTx)
b.reader.roTx = b.stateTx
b.reader.ac = b.agg.MakeContext()
b.reader.SetTx(b.stateTx, b.agg.MakeContext())

return nil
}
Expand Down Expand Up @@ -343,7 +325,7 @@ func (b *blockProcessor) applyBlock(
ctx context.Context,
block *types.Block,
) (types.Receipts, error) {
//defer blockExecutionTimer.UpdateDuration(time.Now())
defer mxBlockExecutionTimer.UpdateDuration(time.Now())

header := block.Header()
b.vmConfig.Debug = true
Expand All @@ -369,6 +351,7 @@ func (b *blockProcessor) applyBlock(
}

b.txNum++ // Pre-block transaction
mxTxProcessed.Inc()
b.writer.w.SetTxNum(b.txNum)
if err := b.writer.w.FinishTx(); err != nil {
return nil, fmt.Errorf("finish pre-block tx %d (block %d) has failed: %w", b.txNum, block.NumberU64(), err)
Expand Down Expand Up @@ -415,6 +398,7 @@ func (b *blockProcessor) applyBlock(
}
}
b.txNum++
mxTxProcessed.Inc()
b.writer.w.SetTxNum(b.txNum)
}

Expand Down Expand Up @@ -456,6 +440,7 @@ func (b *blockProcessor) applyBlock(
}

b.txNum++ // Post-block transaction
mxTxProcessed.Inc()
b.writer.w.SetTxNum(b.txNum)
if b.txNum >= b.startTxNum {
if block.Number().Uint64()%uint64(commitmentFreq) == 0 {
Expand All @@ -473,6 +458,8 @@ func (b *blockProcessor) applyBlock(
}
}

mxTxProcessed.Inc()
mxBlockProcessed.Inc()
return receipts, nil
}

Expand All @@ -486,6 +473,16 @@ type WriterWrapper4 struct {
w *libstate.Aggregator
}

func WrapAggregator(agg *libstate.Aggregator, roTx kv.Tx) (*WriterWrapper4, *ReaderWrapper4) {
return &WriterWrapper4{w: agg}, &ReaderWrapper4{ac: agg.MakeContext(), roTx: roTx}
}

func (rw *ReaderWrapper4) SetTx(roTx kv.Tx, ctx *libstate.AggregatorContext) {
rw.roTx = roTx
rw.ac.Close()
rw.ac = ctx
}

func (rw *ReaderWrapper4) ReadAccountData(address libcommon.Address) (*accounts.Account, error) {
enc, err := rw.ac.ReadAccountData(address.Bytes(), rw.roTx)
if err != nil {
Expand Down
26 changes: 7 additions & 19 deletions cmd/state/commands/erigon4.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (

"github.com/VictoriaMetrics/metrics"
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/commitment"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"

"github.com/ledgerwatch/erigon-lib/commitment"

chain2 "github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/dbg"
Expand Down Expand Up @@ -52,7 +53,7 @@ func init() {

erigon4Cmd.Flags().IntVar(&commitmentFrequency, "commfreq", 25000, "how many blocks to skip between calculating commitment")
erigon4Cmd.Flags().BoolVar(&commitments, "commitments", false, "set to true to calculate commitments")
erigon4Cmd.Flags().StringVar(&commitmentsMode, "commitments.mode", "direct", "defines the way to calculate commitments: 'direct' mode reads from state directly, 'update' accumulate updates before commitment")
erigon4Cmd.Flags().StringVar(&commitmentMode, "commitments.mode", "direct", "defines the way to calculate commitments: 'direct' mode reads from state directly, 'update' accumulate updates before commitment")
erigon4Cmd.Flags().Uint64Var(&startTxNumFrom, "tx", 0, "tx number to start from")
erigon4Cmd.Flags().StringVar(&commitmentTrie, "commitments.trie", "hex", "hex - use Hex Patricia Hashed Trie for commitments, bin - use of binary patricia trie")
erigon4Cmd.Flags().IntVar(&height, "height", 32, "amount of steps in biggest file")
Expand All @@ -63,7 +64,7 @@ func init() {

var (
startTxNumFrom uint64 // flag --tx
commitmentsMode string // flag --commitments.mode [direct|update]
commitmentMode string // flag --commitments.mode [direct|update]
logInterval = 30 * time.Second // time period to print aggregation stat to log
dirtySpaceThreshold = uint64(2 * 1024 * 1024 * 1024) /* threshold of dirty space in MDBX transaction that triggers a commit */
commitmentFrequency int // How many blocks to skip between calculating commitment
Expand Down Expand Up @@ -134,24 +135,11 @@ func Erigon4(genesis *core.Genesis, chainConfig *chain2.Config, logger log.Logge
return err
}

var trieVariant commitment.TrieVariant
switch commitmentTrie {
case "bin":
trieVariant = commitment.VariantBinPatriciaTrie
trieVariant := commitment.ParseTrieVariant(commitmentTrie)
if trieVariant != commitment.VariantHexPatriciaTrie {
blockRootMismatchExpected = true
case "hex":
fallthrough
default:
trieVariant = commitment.VariantHexPatriciaTrie
}

var mode libstate.CommitmentMode
switch commitmentsMode {
case "update":
mode = libstate.CommitmentModeUpdate
default:
mode = libstate.CommitmentModeDirect
}
mode := libstate.ParseCommitmentMode(commitmentMode)

logger.Info("aggregator commitment trie", "variant", trieVariant, "mode", mode.String())

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/ledgerwatch/erigon
go 1.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230310035333-b5e57bcb4740
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3
github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down Expand Up @@ -53,6 +52,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/julienschmidt/httprouter v1.3.0
github.com/kevinburke/go-bindata v3.21.0+incompatible
github.com/ledgerwatch/erigon-lib v0.0.0-20230310185843-dab96dc7c35a
github.com/libp2p/go-libp2p v0.25.1
github.com/libp2p/go-libp2p-pubsub v0.9.1-0.20230221111042-3dbc2fd5baca
github.com/maticnetwork/crand v1.0.2
Expand Down Expand Up @@ -162,6 +162,7 @@ require (
github.com/koron/go-ssdp v0.0.3 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/ledgerwatch/interfaces v0.0.0-20230306115306-76f49663a127 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
Expand All @@ -175,6 +176,7 @@ require (
github.com/lispad/go-generics-tools v1.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/matryer/moq v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,14 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230310035333-b5e57bcb4740 h1:PsXOtJ8AgsM4u4VZWAqQszSJ/1wTVHJqobVfx9kip0Q=
github.com/ledgerwatch/erigon-lib v0.0.0-20230310035333-b5e57bcb4740/go.mod h1:sKLWgIyFuajTu7nu+cahKhReP+CZW57R5jFUYtzvn44=
github.com/ledgerwatch/erigon-lib v0.0.0-20230310173430-4f99fe1d29e0 h1:ChB53Gjza1ZpQJLcKG4hneoeC9msUVw4t5Wo7J+VvSQ=
github.com/ledgerwatch/erigon-lib v0.0.0-20230310173430-4f99fe1d29e0/go.mod h1:sKLWgIyFuajTu7nu+cahKhReP+CZW57R5jFUYtzvn44=
github.com/ledgerwatch/erigon-lib v0.0.0-20230310185843-dab96dc7c35a h1:wsf5rhh6yAy2f6YylC246R+ip2h4lzqaWBaZY7B7mL0=
github.com/ledgerwatch/erigon-lib v0.0.0-20230310185843-dab96dc7c35a/go.mod h1:sKLWgIyFuajTu7nu+cahKhReP+CZW57R5jFUYtzvn44=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20230306115306-76f49663a127 h1:9tPGDgLCC3tJcqMtC+nmYWv54/GE8Y3pWee8GaX3L6o=
github.com/ledgerwatch/interfaces v0.0.0-20230306115306-76f49663a127/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
github.com/ledgerwatch/log/v3 v3.7.0/go.mod h1:J2Jl6zV/58LeA6LTaVVnCGyf1/cYYSEOOLHY4ZN8S2A=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=
Expand Down Expand Up @@ -571,6 +575,8 @@ github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgUR
github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg=
github.com/maticnetwork/polyproto v0.0.2 h1:cPxuxbIDItdwGnucc3lZB58U8Zfe1mH73PWTGd15554=
github.com/maticnetwork/polyproto v0.0.2/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/matryer/moq v0.3.1 h1:kLDiBJoGcusWS2BixGyTkF224aSCD8nLY24tj/NcTCs=
github.com/matryer/moq v0.3.1/go.mod h1:RJ75ZZZD71hejp39j4crZLsEDszGk6iH4v4YsWFKH4s=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand Down