Skip to content

Commit

Permalink
[PVM] wip
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Nov 5, 2024
1 parent 28222cc commit 9404237
Show file tree
Hide file tree
Showing 2 changed files with 405 additions and 250 deletions.
69 changes: 34 additions & 35 deletions vms/platformvm/txs/executor/camino_tx_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"errors"
"fmt"
"reflect"

"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database"
Expand Down Expand Up @@ -106,6 +105,7 @@ var (
errWrongAdminProposal = errors.New("this type of proposal can't be admin-proposal")
errNotPermittedToCreateProposal = errors.New("don't have permission to create proposal of this type")
errZeroDepositOfferLimits = errors.New("deposit offer TotalMaxAmount and TotalMaxRewardAmount are zero")
errAddrStateNotChanged = errors.New("address state wasn't changed")

ErrInvalidProposal = errors.New("proposal is semantically invalid")
)
Expand Down Expand Up @@ -504,19 +504,21 @@ func (e *CaminoProposalTxExecutor) RewardValidatorTx(tx *txs.RewardValidatorTx)
return errWrongCredentialsNumber
}

ins, outs, err := e.FlowChecker.Unlock(e.OnCommitState, []ids.ID{tx.TxID}, locked.StateBonded)
expectedIns, expectedOuts, err := e.FlowChecker.Unlock(
e.OnCommitState,
[]ids.ID{tx.TxID},
locked.StateBonded,
)
if err != nil {
return err
}

expectedTx := &txs.CaminoRewardValidatorTx{
RewardValidatorTx: *tx,
Ins: ins,
Outs: outs,
if !inputsAreEqual(caminoTx.Ins, expectedIns) {
return fmt.Errorf("%w: invalid inputs", errInvalidSystemTxBody)
}

if !reflect.DeepEqual(caminoTx, expectedTx) {
return errInvalidSystemTxBody
if !outputsAreEqual(caminoTx.Outs, expectedOuts) {
return fmt.Errorf("%w: invalid outputs", errInvalidSystemTxBody)
}

var currentStakerToRemove *state.Staker
Expand Down Expand Up @@ -591,33 +593,30 @@ func (e *CaminoProposalTxExecutor) RewardValidatorTx(tx *txs.RewardValidatorTx)
} else {
e.OnCommitState.DeleteDeferredValidator(stakerToRemove)
e.OnAbortState.DeleteDeferredValidator(stakerToRemove)
// Reset deferred bit on node owner address for onCommitState
nodeOwnerAddressOnCommit, err := e.OnCommitState.GetShortIDLink(
ids.ShortID(stakerToRemove.NodeID),
state.ShortLinkKeyRegisterNode,
)
if err != nil {
return err
}
nodeOwnerAddressStateOnCommit, err := e.OnCommitState.GetAddressStates(nodeOwnerAddressOnCommit)
if err != nil {
return err
}
e.OnCommitState.SetAddressStates(nodeOwnerAddressOnCommit, nodeOwnerAddressStateOnCommit&^as.AddressStateNodeDeferred)

// Reset deferred bit on node owner address for onAbortState
nodeOwnerAddressOnAbort, err := e.OnAbortState.GetShortIDLink(
ids.ShortID(stakerToRemove.NodeID),
state.ShortLinkKeyRegisterNode,
)
if err != nil {
return err
}
nodeOwnerAddressStateOnAbort, err := e.OnAbortState.GetAddressStates(nodeOwnerAddressOnAbort)
if err != nil {
return err
if e.Config.IsBerlinPhaseActivated(currentChainTime) {
// Reset deferred bit on node owner address
nodeOwnerAddress, err := e.OnCommitState.GetShortIDLink(
ids.ShortID(stakerToRemove.NodeID),
state.ShortLinkKeyRegisterNode,
)
if err != nil {
return err
}
nodeOwnerAddressState, err := e.OnCommitState.GetAddressStates(nodeOwnerAddress)
if err != nil {
return err
}

// TODO @evlekht if after Berlin we don't have any txs that hit this if, we can move it up, before phase if block
if nodeOwnerAddressState.IsNot(as.AddressStateNodeDeferred) {
return errAddrStateNotChanged
}

addrState := nodeOwnerAddressState &^ as.AddressStateNodeDeferred
e.OnCommitState.SetAddressStates(nodeOwnerAddress, addrState)
e.OnAbortState.SetAddressStates(nodeOwnerAddress, addrState)
}
e.OnAbortState.SetAddressStates(nodeOwnerAddressOnAbort, nodeOwnerAddressStateOnAbort&^as.AddressStateNodeDeferred)
}

txID := e.Tx.ID()
Expand Down Expand Up @@ -2069,8 +2068,6 @@ func (e *CaminoStandardTxExecutor) FinishProposalsTx(tx *txs.FinishProposalsTx)
return err
}

// TODO @evlekht change rewardValidator tx in the same manner

if !inputsAreEqual(tx.Ins, expectedIns) {
return fmt.Errorf("%w: invalid inputs", errInvalidSystemTxBody)
}
Expand Down Expand Up @@ -2354,6 +2351,8 @@ func (e *CaminoStandardTxExecutor) AddressStateTx(tx *txs.AddressStateTx) error
// Set the new state if changed
if addrState != newAddrState {
e.State.SetAddressStates(tx.Address, newAddrState)
// } else {
// return errAddrStateNotChanged
}

// Consume the UTXOS
Expand Down
Loading

0 comments on commit 9404237

Please sign in to comment.