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

Implement signature validation #11

Merged
merged 3 commits into from
Apr 12, 2024
Merged

Conversation

pablomendezroyo
Copy link
Contributor

@pablomendezroyo pablomendezroyo commented Apr 12, 2024

Implement signature validation with go routines. Add testing to validation package.

// Insert into MongoDB if signature is valid
for _, req := range requestsWithActiveValidators {
// create a goroutine for each request
wg.Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure this limits goroutiens to enter "validateAndInsertSignature" one by one, only one at a time. In oracle we use mutex to achieve this (see https://github.com/dappnode/mev-sp-oracle/blob/01cfadc41b4cbd7a334950e2b0e46a2901ee692c/oracle/oracle.go#L73).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to docs

sync.WaitGroup is used to wait for a collection of goroutines to finish executing. You increment the WaitGroup counter for each goroutine you launch and decrement it (wg.Done()) in each goroutine when it finishes its task.
sync.Mutex is used to ensure that only one goroutine accesses a particular section of code at a time. It's typically used to protect shared resources from concurrent access issues, such as race conditions.

It does not look like our case to use Mutex

return validRequests, nil
}

func validateAndInsertSignature(req types.SignatureRequestDecoded, dbCollection *mongo.Collection, wg *sync.WaitGroup) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these helper methods go somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leve them there as for now

@pablomendezroyo pablomendezroyo merged commit a24c936 into main Apr 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants