@@ -131,14 +131,18 @@ func (r *UpdateResponder) Reject(ctx context.Context, reason string) error {
131131 return r .channel .handleUpdateRej (ctx , r .pidx , r .req , reason )
132132}
133133
134- // Update updates the channel state using the update function and proposes the
135- // new state to all other channel participants. The update function must not
136- // update the version counter.
134+ // Update proposes a state update to the channel participants as
135+ // specified by the `updater` function.
136+ //
137+ // The updater function must adhere to the following rules:
138+ // - The version must not be changed. It is incremented automatically.
139+ // - The assets must not be changed.
140+ // - The locked allocation must not be changed.
137141//
138142// Returns nil if all peers accept the update. Returns RequestTimedOutError if
139143// any peer did not respond before the context expires or is cancelled. Returns
140144// an error if any runtime error occurs or any peer rejects the update.
141- func (c * Channel ) Update (ctx context.Context , update func (* channel.State ) error ) ( err error ) {
145+ func (c * Channel ) Update (ctx context.Context , updater func (* channel.State )) error {
142146 if ctx == nil {
143147 return errors .New ("context must not be nil" )
144148 }
@@ -152,9 +156,7 @@ func (c *Channel) Update(ctx context.Context, update func(*channel.State) error)
152156 return c .update (ctx ,
153157 func (state * channel.State ) error {
154158 // apply update
155- if err := update (state ); err != nil {
156- return err
157- }
159+ updater (state )
158160
159161 // validate
160162 return c .validTwoPartyUpdateState (state )
@@ -239,9 +241,9 @@ func (c *Channel) checkUpdateError(ctx context.Context, updateErr error) {
239241 }
240242}
241243
242- func (c * Channel ) update (ctx context.Context , update func (* channel.State ) error ) (err error ) {
244+ func (c * Channel ) update (ctx context.Context , updater func (* channel.State ) error ) (err error ) {
243245 state := c .machine .State ().Clone ()
244- if err := update (state ); err != nil {
246+ if err := updater (state ); err != nil {
245247 return err
246248 }
247249 state .Version ++
0 commit comments