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

Added mining for POS #3187

Merged
merged 20 commits into from
Jan 4, 2022
Merged

Added mining for POS #3187

merged 20 commits into from
Jan 4, 2022

Conversation

Giulio2002
Copy link
Contributor

No description provided.

@Giulio2002 Giulio2002 marked this pull request as draft December 29, 2021 23:43
@Giulio2002
Copy link
Contributor Author

Giulio2002 commented Dec 31, 2021

The Proposing process works as following:

  • We start the PoS proposer by using the --proposer flag, unlike --mine it does not require etherbase to be set
  • We have a thread which at intervals updates the payloads using the transaction pool in ethbackend.go
  • if etherbase is set, we set block's fee recipient to it, if it is not set, then we use the suggestedFeeRecipient
  • There is some clocking between the ethbackend thread and the proposer thread, the ethbackend starts a timer when getPayloadV1 is invoked to make sure that we gave some time for the proposer thread to update/compute the block. we can do 1 block/second with no problem which is Ethereum's limit anyway (--time-per-slot=1s in mergemock).
  • The value of the proposer flag is also passed to ethbackend to prevent access to GetPayloadV1 and ForkChoiceUpdatedV1 (assemble case only) with a proper error, i decided not to start the goroutine in the constructor of the backend server but in backend.go, just personal taste but it can be changed.

@Giulio2002 Giulio2002 marked this pull request as ready for review December 31, 2021 17:38
) *EthBackendServer {
return &EthBackendServer{ctx: ctx, eth: eth, events: events, db: db, blockReader: blockReader, config: config,
reverseDownloadCh: reverseDownloadCh, statusCh: statusCh, waitingForBeaconChain: waitingForBeaconChain,
pendingPayloads: make(map[uint64]types2.ExecutionPayload),
pendingPayloads: make(map[uint64]types2.ExecutionPayload), skipCycleHack: skipCycleHack,
assemblePayloadPOS: assemblePayloadPOS, proposing: proposing, condPauseAssemble: *sync.NewCond(&sync.Mutex{}),
Copy link
Member

Choose a reason for hiding this comment

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

You don't need a separate mutex for condPauseAssemble: just re-use mu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot do that as reusing mu, would cause mu.Lock be called multiple times without any unlocks aka. stalling everything. the reason of this is that what Wait essentially does is locking the mutex, so we cannot reuse the same mutex. same goes with Broadcast, which essentially unlocks the mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that we pass in a pointer, not just a value

Copy link
Member

Choose a reason for hiding this comment

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

I've double checked https://pkg.go.dev/sync#Cond.Wait and the advise is to check for a condition in a loop. So we can use a single sync.Cond (and its mutex) for everything, just with different checks. I've submitted 4de1c30 to that effect.

@Giulio2002 Giulio2002 merged commit 195eb9a into devel Jan 4, 2022
@Giulio2002 Giulio2002 deleted the mining-pos branch January 4, 2022 17:37
@VBulikov VBulikov mentioned this pull request Feb 5, 2025
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.

3 participants