Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
fix time bug
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Feb 1, 2024
1 parent 46fa37a commit 60a34da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cosmos/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ is-validator = {{ .Polaris.Polar.IsValidator }}
force-forward-recheck-txs = {{ .Polaris.Polar.ForceForwardReCheckTxs }}
# Chain config
[polaris.polar.chain]
[polaris.polar.chain] cccccbgkuclekfkddebkvictfhu
chain-id = "{{ .Polaris.Polar.Chain.ChainID }}"
# Homestead switch block
Expand Down
28 changes: 16 additions & 12 deletions cosmos/runtime/txpool/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (m *Mempool) AnteHandle(
if wet, ok := utils.GetAs[*types.WrappedEthereumTransaction](msgs[0]); ok {
ethTx := wet.Unwrap()
if shouldEject := m.shouldEjectFromCometMempool(
ctx.BlockTime(), ethTx,
ethTx,
); shouldEject {
telemetry.IncrCounter(float32(1), MetricKeyAnteEjectedTxs)
return ctx, errors.New("eject from comet mempool")
Expand All @@ -64,15 +64,15 @@ func (m *Mempool) AnteHandle(

// shouldEject returns true if the transaction should be ejected from the CometBFT mempool.
func (m *Mempool) shouldEjectFromCometMempool(
currentTime time.Time, tx *ethtypes.Transaction,
tx *ethtypes.Transaction,
) bool {
defer telemetry.MeasureSince(time.Now(), MetricKeyTimeShouldEject)
if tx == nil {
return false
}

// First check things that are stateless.
if m.validateStateless(tx, currentTime) {
if m.validateStateless(tx) {
return true
}

Expand All @@ -81,20 +81,24 @@ func (m *Mempool) shouldEjectFromCometMempool(
}

// validateStateless returns whether the tx of the given hash is stateless.
func (m *Mempool) validateStateless(tx *ethtypes.Transaction, currentTime time.Time) bool {
// 1. If the transaction has been in the mempool for longer than the configured timeout.
expired := currentTime.Sub(m.crc.TimeFirstSeen(tx.Hash())) > m.lifetime
if expired {
telemetry.IncrCounter(float32(1), MetricKeyAnteShouldEjectExpiredTx)
}

// 2. If the transaction's gas params are less than or equal to the configured limit.
func (m *Mempool) validateStateless(tx *ethtypes.Transaction) bool {
// 1. If the transaction's gas params are less than or equal to the configured limit.
priceLeLimit := tx.GasPrice().Cmp(m.priceLimit) <= 0
if priceLeLimit {
telemetry.IncrCounter(float32(1), MetricKeyAnteShouldEjectPriceLimit)
}

return expired || priceLeLimit
// 2. If the transaction has been in the mempool for longer than the configured timeout.
tfs, found := m.crc.TimeFirstSeen(tx.Hash())
if !found {
return false
}

expired := time.Since(tfs) > m.lifetime
if expired {
telemetry.IncrCounter(float32(1), MetricKeyAnteShouldEjectExpiredTx)
}
return priceLeLimit || expired
}

// includedCanonicalChain returns whether the tx of the given hash is included in the canonical
Expand Down
7 changes: 3 additions & 4 deletions cosmos/runtime/txpool/comet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
type CometRemoteCache interface {
IsRemoteTx(txHash common.Hash) bool
MarkRemoteSeen(txHash common.Hash) bool
TimeFirstSeen(txHash common.Hash) time.Time
TimeFirstSeen(txHash common.Hash) (time.Time, bool)
}

// Thread-safe implementation of CometRemoteCache.
Expand All @@ -63,7 +63,6 @@ func (crc *cometRemoteCache) MarkRemoteSeen(txHash common.Hash) bool {
return false
}

func (crc *cometRemoteCache) TimeFirstSeen(txHash common.Hash) time.Time {
i, _ := crc.timeInserted.Get(txHash)
return i
func (crc *cometRemoteCache) TimeFirstSeen(txHash common.Hash) (time.Time, bool) {
return crc.timeInserted.Get(txHash)
}

0 comments on commit 60a34da

Please sign in to comment.