Skip to content

Commit

Permalink
core: Allows Os received payments while pending activation
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Dec 21, 2021
1 parent 832166f commit a925222
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/orch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ func TestProcessPayment_ActiveOrchestrator(t *testing.T) {

// orchestrator inactive -> error
err := orch.ProcessPayment(defaultPayment(t), ManifestID("some manifest"))
expErr := fmt.Sprintf("orchestrator %v is inactive in round %v, cannot process payments", addr.Hex(), 10)
expErr := fmt.Sprintf("orchestrator %v is not eligible for payments in round %v, cannot process payments", addr.Hex(), 10)
assert.EqualError(err, expErr)

// orchestrator is active -> no error
Expand Down Expand Up @@ -1207,13 +1207,13 @@ func TestIsActive(t *testing.T) {
}
orch := NewOrchestrator(n, rm)

ok, err := orch.isActive(addr)
ok, err := orch.isPaymentEligible(addr)
assert.True(ok)
assert.NoError(err)

// inactive
rm.round = big.NewInt(1000)
ok, err = orch.isActive(addr)
ok, err = orch.isPaymentEligible(addr)
assert.False(ok)
assert.NoError(err)
}
Expand Down
10 changes: 6 additions & 4 deletions core/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func (orch *orchestrator) ProcessPayment(payment net.Payment, manifestID Manifes
sender := ethcommon.BytesToAddress(payment.Sender)

recipientAddr := ethcommon.BytesToAddress(payment.TicketParams.Recipient)
ok, err := orch.isActive(recipientAddr)
ok, err := orch.isPaymentEligible(recipientAddr)
if err != nil {
return err
}

if !ok {
return fmt.Errorf("orchestrator %v is inactive in round %v, cannot process payments", recipientAddr.Hex(), orch.rm.LastInitializedRound())
return fmt.Errorf("orchestrator %v is not eligible for payments in round %v, cannot process payments", recipientAddr.Hex(), orch.rm.LastInitializedRound())
}

priceInfo := payment.GetExpectedPrice()
Expand Down Expand Up @@ -350,9 +350,11 @@ func (orch *orchestrator) AuthToken(sessionID string, expiration int64) *net.Aut
}
}

func (orch *orchestrator) isActive(addr ethcommon.Address) (bool, error) {
func (orch *orchestrator) isPaymentEligible(addr ethcommon.Address) (bool, error) {
// Accept payments when already activated or will be activated in the next round
nextRound := new(big.Int).Add(orch.rm.LastInitializedRound(), big.NewInt(1))
filter := &common.DBOrchFilter{
CurrentRound: orch.rm.LastInitializedRound(),
CurrentRound: nextRound,
Addresses: []ethcommon.Address{addr},
}
orchs, err := orch.node.Database.SelectOrchs(filter)
Expand Down

0 comments on commit a925222

Please sign in to comment.