Skip to content

Commit

Permalink
Update ride generating balance during Ride script executing after Lig…
Browse files Browse the repository at this point in the history
…ht Node activation.
  • Loading branch information
nickeskov committed Oct 17, 2024
1 parent eb49725 commit 8b2496d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/ride/diff_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (db *diffBalance) effectiveBalance() (int64, error) {
return v2, nil
}

func (db *diffBalance) toFullWavesBalance() (*proto.FullWavesBalance, error) {
func (db *diffBalance) toFullWavesBalance(lightNodeActivated bool) (*proto.FullWavesBalance, error) {
eff, err := db.effectiveBalance()
if err != nil {
return nil, err
Expand All @@ -118,9 +118,13 @@ func (db *diffBalance) toFullWavesBalance() (*proto.FullWavesBalance, error) {
if spb < 0 {
return nil, errors.New("negative spendable balance")
}
gen := eff
if db.stateGenerating < gen {
gen = db.stateGenerating
// According to the scala node implementation:
// Before Light Node activation generating balance doesn't change during the script execution.
// Update generating balance if it's greater than effective balance, i.e. update generating balance during
// script processing.
gen := db.stateGenerating
if lightNodeActivated && eff < gen {
gen = eff
}
return &proto.FullWavesBalance{
Regular: uint64(db.balance),
Expand Down
4 changes: 3 additions & 1 deletion pkg/ride/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type WrappedState struct {
dataEntriesSize int
rootScriptLibVersion ast.LibraryVersion
rootActionsCountValidator proto.ActionsCountValidator
isLightNodeActivated bool
}

func newWrappedState(
Expand All @@ -42,6 +43,7 @@ func newWrappedState(
height: proto.Height(env.height()),
rootScriptLibVersion: rootScriptLibVersion,
rootActionsCountValidator: proto.NewScriptActionsCountValidator(),
isLightNodeActivated: env.lightNodeActivated(),
}
}

Expand Down Expand Up @@ -157,7 +159,7 @@ func (ws *WrappedState) NewestFullWavesBalance(account proto.Recipient) (*proto.
if err != nil {
return nil, err
}
return b.toFullWavesBalance()
return b.toFullWavesBalance(ws.isLightNodeActivated)
}

func (ws *WrappedState) IsStateUntouched(account proto.Recipient) (bool, error) {
Expand Down

0 comments on commit 8b2496d

Please sign in to comment.