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

Drop Pending Stakers 2 - Replace txs.ScheduledStaker with txs.Staker #2305

Merged
merged 74 commits into from
Dec 7, 2023

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Nov 14, 2023

Why this should be merged

We chance NewCurrentStaker signature to allow specifying a staking start time that is not necessarily that indicated into the staker transaction.

How this works

Slicing #2175 up

How this was tested

CI

@abi87 abi87 changed the base branch from master to dev November 14, 2023 15:54
@@ -545,3 +532,34 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error {
avax.Produce(e.State, e.Tx.ID(), tx.Outs)
return nil
}

// addStakerFromStakerTx creates the staker and adds it to state.
func (e *StandardTxExecutor) addStakerFromStakerTx(stakerTx txs.Staker) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just a scaffolding. In next PRs we'll handle here (and here alone) the creation of PostDurango stakers

func NewCurrentStaker(
txID ids.ID,
staker txs.PostDurangoStaker,
startTime time.Time,
Copy link
Contributor Author

@abi87 abi87 Nov 14, 2023

Choose a reason for hiding this comment

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

This is the main point of this PR. Upon drop of pending stakers, we'll explicitly pass chainTime here to create the staker object. In this PR we anticipate the structural change by spreading use of txs.Staker instead of txs.ScheduledStaker wherever possible

staker, err := NewCurrentStaker(txID, stakerTx, metadata.PotentialReward)
staker, err := NewCurrentStaker(
txID,
stakerTx.(txs.PostDurangoStaker),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is safe because all of our StakerTxs are also PostDurangoStakerTxs and viceversa. We type assert it for each transaction.
Still ain't pretty

@abi87 abi87 changed the title Introducing PostDurango StakerTx Drop Pending Stakers - introduced PostDurango StakerTx Nov 15, 2023
@abi87 abi87 changed the title Drop Pending Stakers - introduced PostDurango StakerTx Drop Pending Stakers 1 - introduced PostDurango StakerTx Nov 15, 2023
@abi87 abi87 marked this pull request as ready for review November 15, 2023 12:19
@abi87 abi87 requested a review from dhrubabasu November 15, 2023 13:16
Comment on lines 1463 to 1466
stakerTx, ok := tx.Unsigned.(txs.Staker)
if !ok {
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moved up a fewl line. This should never happen, but always better to fail fast.

@abi87 abi87 force-pushed the post_durango_staker_txs branch 2 times, most recently from 5cf9fb6 to 0deb60a Compare November 15, 2023 15:07
Comment on lines 1548 to 1551
stakerTx, ok := tx.Unsigned.(txs.Staker)
if !ok {
return fmt.Errorf("expected tx type txs.Staker but got %T", tx.Unsigned)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moved up a bit. Should never happen but always better to fail fast

@abi87 abi87 force-pushed the post_durango_staker_txs branch from 0deb60a to 8e8ab33 Compare November 15, 2023 15:14
@abi87 abi87 force-pushed the post_durango_staker_txs branch from 8e8ab33 to b213740 Compare November 15, 2023 15:16
@abi87 abi87 changed the base branch from dev to post_durango_staker_txs_0 November 16, 2023 13:21
@abi87 abi87 changed the title Drop Pending Stakers 1 - introduced PostDurango StakerTx Drop Pending Stakers 1 - Replace txs.ScheduledStaker with txs.Staker Nov 16, 2023
Base automatically changed from post_durango_staker_txs_0 to dev December 6, 2023 19:35
staker, err := NewCurrentStaker(
txID,
stakerTx,
stakerTx.(txs.ScheduledStaker).StartTime(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we properly check for the type cast here (and below)? I know this should never be able to fail... and that it will be removed in a followup PR once the startTime is persisted... But I'd prefer to keep the merged code "safe"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@abi87 abi87 requested a review from StephenButtolph December 7, 2023 14:04
@StephenButtolph StephenButtolph added this to the v1.10.18 milestone Dec 7, 2023
@StephenButtolph StephenButtolph added this pull request to the merge queue Dec 7, 2023
Merged via the queue into dev with commit c991157 Dec 7, 2023
16 checks passed
@StephenButtolph StephenButtolph deleted the post_durango_staker_txs branch December 7, 2023 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Drop Pending Stakers
3 participants