-
Notifications
You must be signed in to change notification settings - Fork 18
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
Added a guradian module. #82
base: main
Are you sure you want to change the base?
Conversation
guardian/guardian.go
Outdated
FilterFilePath string // File path to the bloom filter file | ||
PrivateKeyPath string // Path to the private key file | ||
PublicKeyPath string // Path to the public key file | ||
Passphrase string // Passphrase for the private key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these required? If not, better remove them to decrease operational complexity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
guardian/guardian.go
Outdated
|
||
// Reset allows you to reset the Guardian instance. | ||
// This stops the current instance and resets it to nil. | ||
func Reset() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume Reset
should only be called in unit tests, right?
If so, move this function to test dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/txpool/blobpool/blobpool.go
Outdated
@@ -1241,6 +1242,14 @@ func (p *BlobPool) add(tx *types.Transaction) (err error) { | |||
addtimeHist.Update(time.Since(start).Nanoseconds()) | |||
}(time.Now()) | |||
|
|||
// When the guardian module is enabled, check if the sender or recipient in the | |||
// transaction is in the filter file | |||
if instance, err := guardian.GetInstance(); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for filtering blob transactions as eip4844 is not enabled in story right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
guardian/guardian.go
Outdated
// GetInstance returns the singleton Guardian instance, or an error if it is not initialized. | ||
func GetInstance() (*Guardian, error) { | ||
if instance == nil { | ||
return nil, errors.New("guardian is not initialized") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not initialized
is not an error while guardian mode is disabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
guardian/guardian.go
Outdated
|
||
// checkAddress checks if the given address is in the filter list. | ||
func (p *Guardian) checkAddress(tx *types.Transaction, from, addr string) (bool, error) { | ||
ok, err := p.filter.CheckAddress(strings.ToLower(addr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the check is case insensitive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Used to filter transactions from sanctioned addresses.
// newGuardian creates a new Guardian instance from the provided config. | ||
func newGuardian(config Config) (*Guardian, error) { | ||
// Create the secure data handler | ||
handler, err := securedata.NewPGPSecureHandler( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we prefer not using secureHandler
currently.
let's delete all related code and test without secureHandler
func InitInstance(config Config) { | ||
initOnce.Do(func() { | ||
if !config.Enabled { | ||
log.Warn("Guardian is disabled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Guardian mode is disabled by default, this log should be info
level.
Better output a log whether it's disabled or enabled.
// transaction is in the filter file | ||
if instance := guardian.GetInstance(); instance != nil { | ||
if instance.CheckTransaction(pool.signer, tx) { | ||
validTxMeter.Mark(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not use this metric since it's for valid transaction.
I suggest to create a new metric likesanctionedTx
Used to filter transactions from sanctioned addresses.