mirror of
https://github.com/lightninglabs/pool.git
synced 2026-08-13 12:33:04 +02:00
sidecar: add CurrentState() method to side car negotiator
This methods makes writing tests easier as the test context can introspect into the negotiator's state.
This commit is contained in:
parent
3369357053
commit
36dbabd714
1 changed files with 20 additions and 2 deletions
|
|
@ -163,6 +163,8 @@ type AutoAcceptorConfig struct {
|
|||
// provider and recipient of a sidecar channel to complete the manual steps in
|
||||
// automated manner.
|
||||
type SidecarNegotiator struct {
|
||||
currentState uint32
|
||||
|
||||
cfg AutoAcceptorConfig
|
||||
|
||||
wg sync.WaitGroup
|
||||
|
|
@ -172,7 +174,8 @@ type SidecarNegotiator struct {
|
|||
// a valid config.
|
||||
func NewSidecarNegotiator(cfg AutoAcceptorConfig) *SidecarNegotiator {
|
||||
return &SidecarNegotiator{
|
||||
cfg: cfg,
|
||||
cfg: cfg,
|
||||
currentState: uint32(cfg.StartingPkt.CurrentState),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +294,12 @@ func (a *SidecarNegotiator) autoSidecarReceiver(ctx context.Context,
|
|||
continue
|
||||
}
|
||||
|
||||
currentState = newPktState.CurrentState
|
||||
// TODO(roasbeef): make into method for easier
|
||||
// assertions?
|
||||
atomic.StoreUint32(
|
||||
&a.currentState, uint32(newPktState.CurrentState),
|
||||
)
|
||||
|
||||
localTicket = newPktState.ReceiverTicket
|
||||
|
||||
// If our next target state is the completion state,
|
||||
|
|
@ -489,6 +497,10 @@ func (a *SidecarNegotiator) autoSidecarProvider(ctx context.Context, startingPkt
|
|||
currentState = newPktState.CurrentState
|
||||
localTicket = newPktState.ProviderTicket
|
||||
|
||||
atomic.StoreUint32(
|
||||
&a.currentState, uint32(newPktState.CurrentState),
|
||||
)
|
||||
|
||||
switch {
|
||||
case priorState == currentState:
|
||||
fallthrough
|
||||
|
|
@ -515,6 +527,12 @@ func (a *SidecarNegotiator) autoSidecarProvider(ctx context.Context, startingPkt
|
|||
}
|
||||
}
|
||||
|
||||
// CurrentState returns the current state of the sidecar negotiator.
|
||||
func (a *SidecarNegotiator) CurrentState() sidecar.State {
|
||||
state := atomic.LoadUint32(&a.currentState)
|
||||
return sidecar.State(state)
|
||||
}
|
||||
|
||||
// stateStepProvider is the state transition function for the provider of a
|
||||
// sidecar ticket. It takes the current transcript state, the provider's
|
||||
// account, and canned bid and returns a new transition to a new ticket state.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue