Skip to content

Commit 90d0136

Browse files
committed
client: Validate state transition on force update
Signed-off-by: Matthias Geihs <matthias@perun.network>
1 parent 37dfdbf commit 90d0136

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

channel/machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,15 @@ func (m *machine) expect(tr PhaseTransition) error {
475475
return nil
476476
}
477477

478-
// validTransition checks that the transition from the current to the provided
478+
// ValidTransition checks that the transition from the current to the provided
479479
// state is valid. The following checks are run:
480480
// * matching channel ids
481481
// * no transition from final state
482482
// * version increase by 1
483483
// * preservation of balances
484484
// A StateMachine will additionally check the validity of the app-specific
485485
// transition whereas an ActionMachine checks each Action as being valid.
486-
func (m *machine) validTransition(to *State) error {
486+
func (m *machine) ValidTransition(to *State) error {
487487
if to.ID != m.params.id {
488488
return errors.New("new state's ID doesn't match")
489489
}

channel/statemachine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (m *StateMachine) validTransition(to *State, actor Index) (err error) {
134134
if actor >= m.N() {
135135
return errors.New("actor index is out of range")
136136
}
137-
if err := m.machine.validTransition(to); err != nil {
137+
if err := m.machine.ValidTransition(to); err != nil {
138138
return err
139139
}
140140

client/adjudicate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ func (c *Channel) ForceUpdate(ctx context.Context, updater func(*channel.State))
210210
updater(state)
211211
state.Version++
212212

213+
// Check state transition.
214+
if err := c.machine.ValidTransition(state); err != nil {
215+
return errors.WithMessage(err, "validating state transition")
216+
}
217+
213218
// Apply state in machine and generate signature
214219
if err := c.machine.SetProgressing(ctx, state); err != nil {
215220
return errors.WithMessage(err, "updating machine")

0 commit comments

Comments
 (0)