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

Shivam/txpool tracing #604

Merged
merged 102 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
7583a4d
lock, unlock to rlock, runlock
temaniarpit27 Oct 18, 2022
f6d0296
add : tracing Pending() and Locals()
0xsharma Oct 18, 2022
dc0c2a3
Log time spent in committing a tx during mining
cffls Oct 18, 2022
02bc704
Remove data from logging
cffls Oct 18, 2022
a42682e
Move log into case where a tx completes without error
cffls Oct 18, 2022
5d1196a
profile fillTransactions
manav2401 Oct 18, 2022
a734bb6
fix conflict
manav2401 Oct 18, 2022
b8ea548
bug fixes
manav2401 Oct 18, 2022
434a34a
add logs
manav2401 Oct 19, 2022
6c52e18
txpool: add tracing in Pending()
manav2401 Oct 19, 2022
8f31f24
rearrange tracing
JekaMas Oct 19, 2022
4589c0c
add attributes
JekaMas Oct 19, 2022
cc17f36
fix
JekaMas Oct 19, 2022
897bdc0
fix
JekaMas Oct 19, 2022
69e37f9
log error in profiling
manav2401 Oct 19, 2022
198befb
update file mode and file path for profiling
manav2401 Oct 19, 2022
a62ec80
full profiling
JekaMas Oct 19, 2022
a01e2fd
fix
JekaMas Oct 19, 2022
89c5af8
fix log
JekaMas Oct 19, 2022
e55c652
fix log
JekaMas Oct 19, 2022
4fb656f
less wait
JekaMas Oct 19, 2022
bf1ae91
fix
JekaMas Oct 19, 2022
13b08a0
fix
JekaMas Oct 19, 2022
0b72ebb
logs
JekaMas Oct 19, 2022
6bdb879
worker: use block number for prof files
manav2401 Oct 19, 2022
a06f170
initial
JekaMas Oct 20, 2022
8cc2c91
txList add
JekaMas Oct 20, 2022
fead121
fix gas calculation
JekaMas Oct 20, 2022
0eb1bf9
fix
JekaMas Oct 20, 2022
3ff152b
green tests
JekaMas Oct 20, 2022
18585a8
linters
JekaMas Oct 20, 2022
a1e1a1f
prettify
JekaMas Oct 20, 2022
6bc8883
allocate less
JekaMas Oct 21, 2022
ee7f287
no locks between pending and reorg
JekaMas Oct 21, 2022
0663649
no locks
JekaMas Oct 21, 2022
d842779
no locks on locals
JekaMas Oct 22, 2022
55c749a
more tests
JekaMas Oct 22, 2022
0576e91
linters
JekaMas Oct 22, 2022
b5a80fd
less allocs
JekaMas Oct 22, 2022
93ea8a4
comment
JekaMas Oct 22, 2022
8d088a8
optimize errors
JekaMas Oct 22, 2022
dd83fa2
linters
JekaMas Oct 22, 2022
22b8814
fix
JekaMas Oct 22, 2022
7585c1e
fix
JekaMas Oct 22, 2022
df659fc
Linters
JekaMas Oct 22, 2022
8fe4aa9
linters
JekaMas Oct 23, 2022
4487111
Merge branch 'tx-pool-reorg-optimization' of github.com:maticnetwork/…
JekaMas Oct 23, 2022
d5f7520
linters
JekaMas Oct 23, 2022
9ef4278
simplify errors
JekaMas Oct 23, 2022
c052514
atomics for transactions
JekaMas Oct 23, 2022
5866cd5
fix
JekaMas Oct 23, 2022
ab36c33
optimize workers
JekaMas Oct 23, 2022
29277ee
fix copy
JekaMas Oct 23, 2022
f1e3c92
linters
JekaMas Oct 23, 2022
9832c44
txpool tracing
JekaMas Oct 27, 2022
758eb4f
linters
JekaMas Oct 27, 2022
94446dc
merge
JekaMas Oct 27, 2022
468a546
linters
JekaMas Oct 27, 2022
7293551
fix tracing
JekaMas Oct 27, 2022
25f172a
duration in mcs
JekaMas Oct 27, 2022
a1b1295
locks
JekaMas Oct 27, 2022
3aa7b0d
metrics
JekaMas Oct 28, 2022
5b017ac
fix
JekaMas Oct 28, 2022
03385b6
cache hit/miss
JekaMas Oct 28, 2022
79e66f9
less locks on evict
JekaMas Oct 29, 2022
4a1cd65
remove once
JekaMas Oct 30, 2022
1cd8de5
remove once
JekaMas Oct 30, 2022
1571a06
switch off pprof
JekaMas Oct 30, 2022
b39fe2f
fix data race
JekaMas Oct 30, 2022
e2be069
fix data race
JekaMas Oct 30, 2022
323c2f8
add : sealed total/empty blocks metric gauge
0xsharma Oct 31, 2022
abc0149
add : RPC debug_getTraceStack
0xsharma Oct 31, 2022
83ceb46
fix : RPC debug_getTraceStack
0xsharma Oct 31, 2022
dc55f1d
fix : RPC debug_getTraceStack for all go-routines
0xsharma Oct 31, 2022
409886a
linters
JekaMas Nov 1, 2022
665f6d2
add data race test on txpool
JekaMas Nov 2, 2022
0acbb6e
fix concurrency
JekaMas Nov 3, 2022
fbaa968
noleak
JekaMas Nov 3, 2022
ae7e72d
increase batch size
JekaMas Nov 3, 2022
54950ff
prettify
JekaMas Nov 3, 2022
9bb0be4
tests
JekaMas Nov 3, 2022
cec80de
baseFee mutex
JekaMas Nov 3, 2022
764aeb4
panic fix
JekaMas Nov 3, 2022
67e49d6
linters
JekaMas Nov 3, 2022
028961b
fix gas fee data race
JekaMas Nov 3, 2022
f8246e9
linters
JekaMas Nov 3, 2022
8de32f4
more transactions
JekaMas Nov 3, 2022
4c32b4e
debug
JekaMas Nov 9, 2022
6165eec
debug
JekaMas Nov 10, 2022
737d7e6
fix ticker
JekaMas Nov 11, 2022
549d312
fix test
JekaMas Nov 11, 2022
e0f6fe6
add cacheMu
JekaMas Nov 11, 2022
7db77be
more tests
JekaMas Nov 11, 2022
e4178d1
fix test panic
JekaMas Nov 11, 2022
57c4877
linters
JekaMas Nov 12, 2022
b9cedf1
add statistics
JekaMas Nov 12, 2022
ec472db
add statistics
JekaMas Nov 12, 2022
390a04c
txitems data race
JekaMas Nov 12, 2022
618bcfb
fix tx list Has
JekaMas Nov 12, 2022
f9d331b
merge
JekaMas Nov 12, 2022
714d8df
Merge branch 'develop' into shivam/txpool-tracing
0xsharma Nov 29, 2022
0e9f675
fix : lint
0xsharma Nov 29, 2022
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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ ios:
@echo "Import \"$(GOBIN)/Geth.framework\" to use the library."

test:
$(GOTEST) --timeout 5m -shuffle=on -cover -coverprofile=cover.out $(TESTALL)
$(GOTEST) --timeout 5m -shuffle=on -cover -short -coverprofile=cover.out -covermode=atomic $(TESTALL)

test-txpool-race:
$(GOTEST) -run=TestPoolMiningDataRaces --timeout 600m -race -v ./core/

test-race:
$(GOTEST) --timeout 15m -race -shuffle=on $(TESTALL)
Expand All @@ -75,7 +78,7 @@ lint:

lintci-deps:
rm -f ./build/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.48.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.50.1

goimports:
goimports -local "$(PACKAGE)" -w .
Expand Down
3 changes: 2 additions & 1 deletion cmd/evm/internal/t8ntool/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"os"
"strings"

"gopkg.in/urfave/cli.v1"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
Expand All @@ -32,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/tests"
"gopkg.in/urfave/cli.v1"
)

type result struct {
Expand Down
24 changes: 24 additions & 0 deletions common/debug/debug.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package debug

import (
"fmt"
"runtime"
)

Expand All @@ -26,3 +27,26 @@ func Callers(show int) []string {

return callers
}

func CodeLine() (string, string, int) {
pc, filename, line, _ := runtime.Caller(1)
return runtime.FuncForPC(pc).Name(), filename, line
}

func CodeLineStr() string {
pc, filename, line, _ := runtime.Caller(1)
return fmt.Sprintf("%s:%d - %s", filename, line, runtime.FuncForPC(pc).Name())
}

func Stack(all bool) []byte {
buf := make([]byte, 4096)

for {
n := runtime.Stack(buf, all)
if n < len(buf) {
return buf[:n]
}

buf = make([]byte, 2*len(buf))
}
}
29 changes: 25 additions & 4 deletions common/math/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package math
import (
"fmt"
"math/big"

"github.com/holiman/uint256"
)

// Various big integer limit values.
Expand Down Expand Up @@ -132,6 +134,7 @@ func MustParseBig256(s string) *big.Int {
// BigPow returns a ** b as a big integer.
func BigPow(a, b int64) *big.Int {
r := big.NewInt(a)

return r.Exp(r, big.NewInt(b), nil)
}

Expand All @@ -140,6 +143,15 @@ func BigMax(x, y *big.Int) *big.Int {
if x.Cmp(y) < 0 {
return y
}

return x
}

func BigMaxUint(x, y *uint256.Int) *uint256.Int {
if x.Lt(y) {
return y
}

return x
}

Expand All @@ -148,6 +160,15 @@ func BigMin(x, y *big.Int) *big.Int {
if x.Cmp(y) > 0 {
return y
}

return x
}

func BigMinUint256(x, y *uint256.Int) *uint256.Int {
if x.Gt(y) {
return y
}

return x
}

Expand Down Expand Up @@ -227,10 +248,10 @@ func U256Bytes(n *big.Int) []byte {
// S256 interprets x as a two's complement number.
// x must not exceed 256 bits (the result is undefined if it does) and is not modified.
//
// S256(0) = 0
// S256(1) = 1
// S256(2**255) = -2**255
// S256(2**256-1) = -1
// S256(0) = 0
// S256(1) = 1
// S256(2**255) = -2**255
// S256(2**256-1) = -1
func S256(x *big.Int) *big.Int {
if x.Cmp(tt255) < 0 {
return x
Expand Down
23 changes: 23 additions & 0 deletions common/math/uint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package math

import (
"math/big"

"github.com/holiman/uint256"
)

var (
U0 = uint256.NewInt(0)
U1 = uint256.NewInt(1)
U100 = uint256.NewInt(100)
)

func U256LTE(a, b *uint256.Int) bool {
return a.Lt(b) || a.Eq(b)
}

func FromBig(v *big.Int) *uint256.Int {
u, _ := uint256.FromBig(v)

return u
}
9 changes: 9 additions & 0 deletions common/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package common

import "time"

const TimeMilliseconds = "15:04:05.000"

func NowMilliseconds() string {
return time.Now().Format(TimeMilliseconds)
}
10 changes: 8 additions & 2 deletions common/tracing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -51,11 +52,16 @@ func Trace(ctx context.Context, spanName string) (context.Context, trace.Span) {
return tr.Start(ctx, spanName)
}

func Exec(ctx context.Context, spanName string, opts ...Option) {
func Exec(ctx context.Context, instrumentationName, spanName string, opts ...Option) {
var span trace.Span

tr := FromContext(ctx)

if tr == nil && len(instrumentationName) != 0 {
tr = otel.GetTracerProvider().Tracer(instrumentationName)
ctx = WithTracer(ctx, tr)
}

if tr != nil {
ctx, span = tr.Start(ctx, spanName)
}
Expand Down Expand Up @@ -85,7 +91,7 @@ func ElapsedTime(ctx context.Context, span trace.Span, msg string, fn func(conte
fn(ctx, span)

if span != nil {
span.SetAttributes(attribute.Int(msg, int(time.Since(now).Milliseconds())))
span.SetAttributes(attribute.Int(msg, int(time.Since(now).Microseconds())))
}
}

Expand Down
8 changes: 4 additions & 4 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead
if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) {
cx := statefull.ChainContext{Chain: chain, Bor: c}

tracing.Exec(finalizeCtx, "bor.checkAndCommitSpan", func(ctx context.Context, span trace.Span) {
tracing.Exec(finalizeCtx, "", "bor.checkAndCommitSpan", func(ctx context.Context, span trace.Span) {
// check and commit span
err = c.checkAndCommitSpan(finalizeCtx, state, header, cx)
})
Expand All @@ -832,7 +832,7 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead
}

if c.HeimdallClient != nil {
tracing.Exec(finalizeCtx, "bor.checkAndCommitSpan", func(ctx context.Context, span trace.Span) {
tracing.Exec(finalizeCtx, "", "bor.checkAndCommitSpan", func(ctx context.Context, span trace.Span) {
// commit states
stateSyncData, err = c.CommitStates(finalizeCtx, state, header, cx)
})
Expand All @@ -844,7 +844,7 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead
}
}

tracing.Exec(finalizeCtx, "bor.changeContractCodeIfNeeded", func(ctx context.Context, span trace.Span) {
tracing.Exec(finalizeCtx, "", "bor.changeContractCodeIfNeeded", func(ctx context.Context, span trace.Span) {
err = c.changeContractCodeIfNeeded(headerNumber, state)
})

Expand All @@ -854,7 +854,7 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead
}

// No block rewards in PoA, so the state remains as it is
tracing.Exec(finalizeCtx, "bor.IntermediateRoot", func(ctx context.Context, span trace.Span) {
tracing.Exec(finalizeCtx, "", "bor.IntermediateRoot", func(ctx context.Context, span trace.Span) {
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
})

Expand Down
53 changes: 53 additions & 0 deletions consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"math/big"

"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -92,3 +94,54 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
)
}
}

// CalcBaseFee calculates the basefee of the header.
func CalcBaseFeeUint(config *params.ChainConfig, parent *types.Header) *uint256.Int {
var (
initialBaseFeeUint = uint256.NewInt(params.InitialBaseFee)
baseFeeChangeDenominatorUint64 = params.BaseFeeChangeDenominator(config.Bor, parent.Number)
baseFeeChangeDenominatorUint = uint256.NewInt(baseFeeChangeDenominatorUint64)
)

// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number) {
return initialBaseFeeUint.Clone()
}

var (
parentGasTarget = parent.GasLimit / params.ElasticityMultiplier
parentGasTargetBig = uint256.NewInt(parentGasTarget)
)

// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
if parent.GasUsed == parentGasTarget {
return math.FromBig(parent.BaseFee)
}

if parent.GasUsed > parentGasTarget {
// If the parent block used more gas than its target, the baseFee should increase.
gasUsedDelta := uint256.NewInt(parent.GasUsed - parentGasTarget)

parentBaseFee := math.FromBig(parent.BaseFee)
x := gasUsedDelta.Mul(parentBaseFee, gasUsedDelta)
y := x.Div(x, parentGasTargetBig)
baseFeeDelta := math.BigMaxUint(
x.Div(y, baseFeeChangeDenominatorUint),
math.U1,
)

return x.Add(parentBaseFee, baseFeeDelta)
}

// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
gasUsedDelta := uint256.NewInt(parentGasTarget - parent.GasUsed)
parentBaseFee := math.FromBig(parent.BaseFee)
x := gasUsedDelta.Mul(parentBaseFee, gasUsedDelta)
y := x.Div(x, parentGasTargetBig)
baseFeeDelta := x.Div(y, baseFeeChangeDenominatorUint)

return math.BigMaxUint(
x.Sub(parentBaseFee, baseFeeDelta),
math.U0.Clone(),
)
}
17 changes: 13 additions & 4 deletions core/tx_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
if _, err := os.Stat(journal.path); os.IsNotExist(err) {
return nil
}

// Open the journal for loading any past transactions
input, err := os.Open(journal.path)
if err != nil {
return err
}

defer input.Close()

// Temporarily discard any journal additions (don't double add on load)
Expand All @@ -80,29 +82,35 @@ func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
// appropriate progress counters. Then use this method to load all the
// journaled transactions in small-ish batches.
loadBatch := func(txs types.Transactions) {
errs := add(txs)

dropped = len(errs)

for _, err := range add(txs) {
if err != nil {
log.Debug("Failed to add journaled transaction", "err", err)
dropped++
}
log.Debug("Failed to add journaled transaction", "err", err)
}
}
var (
failure error
batch types.Transactions
)

for {
// Parse the next transaction and terminate on error
tx := new(types.Transaction)

if err = stream.Decode(tx); err != nil {
if err != io.EOF {
failure = err
}

if batch.Len() > 0 {
loadBatch(batch)
}

break
}

// New transaction parsed, queue up for later, import if threshold is reached
total++

Expand All @@ -111,6 +119,7 @@ func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
batch = batch[:0]
}
}

log.Info("Loaded local transaction journal", "transactions", total, "dropped", dropped)

return failure
Expand Down
Loading