-
Notifications
You must be signed in to change notification settings - Fork 273
feat: add preconfirmation tx feature (WIP) #1883
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
base: main
Are you sure you want to change the base?
Conversation
@JayT106 your pull request is missing a changelog! |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1883 +/- ##
===========================================
+ Coverage 16.87% 33.28% +16.40%
===========================================
Files 72 132 +60
Lines 6163 13049 +6886
===========================================
+ Hits 1040 4343 +3303
- Misses 5000 8358 +3358
- Partials 123 348 +225
🚀 New features to boost your workflow:
|
} | ||
|
||
// Start cleanup goroutine | ||
go service.cleanupExpiredPreconfirmations() |
Check notice
Code scanning / CodeQL
Spawning a Go routine Note
for _, info := range s.txTracker { | ||
if info.InMempool { | ||
if info.Preconfirmation != nil { | ||
priorityCount++ | ||
totalPriorityLevel += info.Preconfirmation.PriorityLevel | ||
|
||
if info.Status == TxStatusPreconfirmed { | ||
preconfirmedCount++ | ||
} | ||
} | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
stats.PreconfirmedTxs = preconfirmedCount | ||
|
||
if priorityCount > 0 { | ||
stats.AvgPriorityLevel = float32(totalPriorityLevel) / float32(priorityCount) |
Check notice
Code scanning / CodeQL
Floating point arithmetic Note
for _, info := range s.txTracker { | ||
if info.InMempool && info.Preconfirmation != nil { | ||
results = append(results, &PriorityTxInfoResult{ | ||
TxHash: info.TxHash, | ||
PriorityLevel: info.Preconfirmation.PriorityLevel, | ||
Timestamp: info.Timestamp.Unix(), | ||
SizeBytes: uint32(len(info.TxBytes)), | ||
Preconfirmation: info.Preconfirmation, | ||
Position: info.MempoolPosition, | ||
}) | ||
|
||
count++ | ||
if limit > 0 && count >= limit { | ||
break | ||
} | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
|
||
// createPreconfirmation creates a preconfirmation for a transaction | ||
func (s *PriorityTxService) createPreconfirmation(txHash string, priorityLevel uint32) *PreconfirmationInfo { | ||
now := time.Now() |
Check warning
Code scanning / CodeQL
Calling the system time Warning
Status: TxStatusPreconfirmed, | ||
InMempool: true, | ||
Preconfirmation: preconf, | ||
Timestamp: time.Now(), |
Check warning
Code scanning / CodeQL
Calling the system time Warning
for whitelistAddr := range epm.whitelist { | ||
// Check if it's an Ethereum address format (0x...) | ||
if strings.HasPrefix(strings.ToLower(whitelistAddr), "0x") { | ||
if strings.EqualFold(whitelistAddr, ethAddr) { | ||
return true | ||
} | ||
} else { | ||
// Bech32 format comparison | ||
if whitelistAddr == bech32Addr { | ||
return true | ||
} | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
for whitelistAddr := range epm.whitelist { | ||
// Check if it's an Ethereum address format (0x...) | ||
if strings.HasPrefix(strings.ToLower(whitelistAddr), "0x") { | ||
// Case-insensitive comparison for Ethereum addresses | ||
if strings.HasPrefix(strings.ToLower(address), "0x") && strings.EqualFold(whitelistAddr, address) { | ||
return true | ||
} | ||
} else { | ||
// Exact comparison for bech32 format | ||
if whitelistAddr == address { | ||
return true | ||
} | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
for addr := range epm.whitelist { | ||
addresses = append(addresses, addr) | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
} | ||
|
||
// Update status in the copy if preconfirmation expired | ||
if infoCopy.Preconfirmation != nil && time.Now().After(infoCopy.Preconfirmation.ExpiresAt) { |
Check warning
Code scanning / CodeQL
Calling the system time Warning
for _, info := range s.txTracker { | ||
if info.InMempool && info.Preconfirmation != nil { | ||
count++ | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
s.txTrackerLock.Lock() | ||
s.preconfirmationMutex.Lock() | ||
|
||
now := time.Now() |
Check warning
Code scanning / CodeQL
Calling the system time Warning
for txHash, preconf := range s.preconfirmations { | ||
if now.After(preconf.ExpiresAt) { | ||
delete(s.preconfirmations, txHash) | ||
|
||
if info, exists := s.txTracker[txHash]; exists && info.Status == TxStatusPreconfirmed { | ||
info.Status = TxStatusExpired | ||
} | ||
|
||
s.logger.Debug("cleaned up expired preconfirmation", "tx_hash", txHash) | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻
PR Checklist:
make
)make test
)go fmt
)golangci-lint run
)go list -json -m all | nancy sleuth
)Thank you for your code, it's appreciated! :)