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

calculate tx the lifecycle duration #839

Merged
merged 41 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d2014b8
feat: add transactions len metrics of block processer
georgehao Mar 3, 2024
36d5590
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 4, 2024
00a75fa
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 7, 2024
77b8381
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 14, 2024
6be368b
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 18, 2024
d4d1e9a
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 24, 2024
c9b8b4a
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 27, 2024
f01e6c3
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Mar 30, 2024
728ee6c
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Apr 7, 2024
5a34f06
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Apr 8, 2024
4e05762
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Apr 8, 2024
3e2bccc
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Apr 16, 2024
e17a131
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Apr 16, 2024
109b703
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Apr 18, 2024
8d0a496
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao May 6, 2024
a73bbdb
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao May 20, 2024
6753d83
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao May 27, 2024
5c6b619
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao May 29, 2024
d33e5d6
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao May 30, 2024
a7c195b
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Jun 12, 2024
349b625
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Jun 12, 2024
3046c6f
Merge branch 'develop' of github.com:scroll-tech/go-ethereum into dev…
georgehao Jun 17, 2024
91d6ce7
calculate tx lifecycle median duration
georgehao Jun 19, 2024
7a39aaa
chore: auto version bump [bot]
georgehao Jun 19, 2024
4f11137
fix
georgehao Jun 20, 2024
ad3b741
Merge branch 'feat/calculate_tx_duration' of github.com:scroll-tech/g…
georgehao Jun 20, 2024
96b3e93
fix
georgehao Jun 20, 2024
3c2beba
fix
georgehao Jun 20, 2024
810b17e
fix conflict
georgehao Aug 7, 2024
837675d
chore: auto version bump [bot]
georgehao Aug 7, 2024
ba2c58d
address comments
georgehao Aug 8, 2024
6f54373
Merge branch 'feat/calculate_tx_duration' of github.com:scroll-tech/g…
georgehao Aug 8, 2024
4609db7
remove error code
georgehao Aug 12, 2024
bf7b342
Merge branch 'develop' into feat/calculate_tx_duration
georgehao Aug 12, 2024
96dd0c2
address comment
georgehao Aug 12, 2024
4b0ebd1
update
georgehao Aug 12, 2024
45ba630
Update core/tx_pool.go
omerfirmak Aug 13, 2024
8f64c7c
Update core/types/transaction.go
omerfirmak Aug 13, 2024
1a14ddb
Update core/tx_pool.go
georgehao Aug 13, 2024
396a0b4
Merge branch 'develop' into feat/calculate_tx_duration
georgehao Aug 13, 2024
d543633
Update core/tx_pool.go
colinlyguo Aug 13, 2024
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
24 changes: 24 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ var (
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)

reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)

txLifecycleTimer = metrics.NewRegisteredTimer("txpool/txfifecycle", nil)
)

// TxStatus is the current status of a transaction as seen by the pool.
Expand Down Expand Up @@ -795,6 +797,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
// New transaction is better, replace old one
if old != nil {
pool.all.Remove(old.Hash())
pool.calculateTxsLifecycle(types.Transactions{old}, time.Now())
pool.priced.Removed(1)
pendingReplaceMeter.Mark(1)
}
Expand Down Expand Up @@ -848,6 +851,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction, local boo
if old != nil {
pool.all.Remove(old.Hash())
pool.priced.Removed(1)
pool.calculateTxsLifecycle(types.Transactions{old}, time.Now())
queuedReplaceMeter.Mark(1)
} else {
// Nothing was replaced, bump the queued counter
Expand Down Expand Up @@ -896,13 +900,15 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
if !inserted {
// An older transaction was better, discard this
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
pool.priced.Removed(1)
pendingDiscardMeter.Mark(1)
return false
}
// Otherwise discard any previous transaction and mark this
if old != nil {
pool.all.Remove(old.Hash())
pool.calculateTxsLifecycle(types.Transactions{old}, time.Now())
pool.priced.Removed(1)
pendingReplaceMeter.Mark(1)
} else {
Expand Down Expand Up @@ -1084,6 +1090,7 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {

// Remove it from the list of known transactions
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
if outofbound {
pool.priced.Removed(1)
}
Expand Down Expand Up @@ -1418,6 +1425,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _, tx := range forwards {
hash := tx.Hash()
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
}
log.Trace("Removed old queued transactions", "count", len(forwards))

Expand All @@ -1427,6 +1435,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _, tx := range drops {
hash := tx.Hash()
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
}
log.Trace("Removed unpayable queued transactions", "count", len(drops))
queuedNofundsMeter.Mark(int64(len(drops)))
Expand All @@ -1449,6 +1458,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _, tx := range caps {
hash := tx.Hash()
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
}
queuedRateLimitMeter.Mark(int64(len(caps)))
Expand Down Expand Up @@ -1531,6 +1541,7 @@ func (pool *TxPool) truncatePending() {
// Drop the transaction from the global pools too
hash := tx.Hash()
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())

// Update the account nonce to the dropped transaction
pool.pendingNonces.setIfLower(offenders[i], tx.Nonce())
Expand Down Expand Up @@ -1558,6 +1569,7 @@ func (pool *TxPool) truncatePending() {
// Drop the transaction from the global pools too
hash := tx.Hash()
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())

// Update the account nonce to the dropped transaction
pool.pendingNonces.setIfLower(addr, tx.Nonce())
Expand Down Expand Up @@ -1637,6 +1649,7 @@ func (pool *TxPool) demoteUnexecutables() {
for _, tx := range olds {
hash := tx.Hash()
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
log.Trace("Removed old pending transaction", "hash", hash)
}
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
Expand All @@ -1646,6 +1659,7 @@ func (pool *TxPool) demoteUnexecutables() {
hash := tx.Hash()
log.Trace("Removed unpayable pending transaction", "hash", hash)
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
}
pendingNofundsMeter.Mark(int64(len(drops)))

Expand Down Expand Up @@ -1681,6 +1695,16 @@ func (pool *TxPool) demoteUnexecutables() {
}
}

// calculateTxLifecycle calculate the txs lifecycle
georgehao marked this conversation as resolved.
Show resolved Hide resolved
func (pool *TxPool) calculateTxsLifecycle(txs types.Transactions, t time.Time) {
for _, tx := range txs {
if tx.Time().Before(t) {
txLifecycle := t.Sub(tx.Time())
txLifecycleTimer.Update(txLifecycle)
}
}
}

// PauseReorgs stops any new reorg jobs to be started but doesn't interrupt any existing ones that are in flight
// Keep in mind this function might block, although it is not expected to block for any significant amount of time
func (pool *TxPool) PauseReorgs() {
Expand Down
5 changes: 5 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
return nil
}

// Time retrieves the time first seen locally
func (tx *Transaction) Time() time.Time {
return tx.time
}

// decodeTyped decodes a typed transaction from the canonical format.
func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
if len(b) <= 1 {
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 6 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down
Loading