Skip to content

Commit

Permalink
client: Validate state transition on force update
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Geihs <[email protected]>
  • Loading branch information
matthiasgeihs committed Jan 28, 2022
1 parent 37dfdbf commit 90d0136
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,15 @@ func (m *machine) expect(tr PhaseTransition) error {
return nil
}

// validTransition checks that the transition from the current to the provided
// ValidTransition checks that the transition from the current to the provided
// state is valid. The following checks are run:
// * matching channel ids
// * no transition from final state
// * version increase by 1
// * preservation of balances
// A StateMachine will additionally check the validity of the app-specific
// transition whereas an ActionMachine checks each Action as being valid.
func (m *machine) validTransition(to *State) error {
func (m *machine) ValidTransition(to *State) error {
if to.ID != m.params.id {
return errors.New("new state's ID doesn't match")
}
Expand Down
2 changes: 1 addition & 1 deletion channel/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (m *StateMachine) validTransition(to *State, actor Index) (err error) {
if actor >= m.N() {
return errors.New("actor index is out of range")
}
if err := m.machine.validTransition(to); err != nil {
if err := m.machine.ValidTransition(to); err != nil {
return err
}

Expand Down
5 changes: 5 additions & 0 deletions client/adjudicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ func (c *Channel) ForceUpdate(ctx context.Context, updater func(*channel.State))
updater(state)
state.Version++

// Check state transition.
if err := c.machine.ValidTransition(state); err != nil {
return errors.WithMessage(err, "validating state transition")
}

// Apply state in machine and generate signature
if err := c.machine.SetProgressing(ctx, state); err != nil {
return errors.WithMessage(err, "updating machine")
Expand Down

0 comments on commit 90d0136

Please sign in to comment.