Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core,pm: handle zero/nil gas price from gas price monitor #1830

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

- \#1810 Display "n/a" in CLI when max gas price isn't specified (@kyriediculous)

#### Orchestrator

- \#1830 handle "zero" or "nil" gas price from gas price monitor (@kyriediculous)

### Features ⚒

#### Broadcaster

- \#1823 Mark more transcoder errors as NonRetryable (@jailuthra)
- \#1823 Mark more transcoder errors as NonRetryable (@jailuthra)
5 changes: 4 additions & 1 deletion core/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ func (orch *orchestrator) priceInfo(sender ethcommon.Address) (*big.Rat, error)
return nil, err
}

overhead = overhead.Add(overhead, new(big.Rat).Inv(txCostMultiplier))
if txCostMultiplier.Cmp(big.NewRat(0, 1)) > 0 {
overhead = overhead.Add(overhead, new(big.Rat).Inv(txCostMultiplier))
}

}
// pricePerPixel = basePrice * overhead
fixedPrice, err := common.PriceToFixed(new(big.Rat).Mul(basePrice, overhead))
Expand Down
11 changes: 9 additions & 2 deletions pm/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ func (r *recipient) TicketParams(sender ethcommon.Address, price *big.Rat) (*Tic
}

func (r *recipient) txCost() *big.Int {
gasPrice := big.NewInt(0)
// Fetch current gasprice from cache through gasPrice monitor
gasPrice := r.gpm.GasPrice()
if gp := r.gpm.GasPrice(); gp != nil {
gasPrice = gp
}
// Return txCost = redeemGas * gasPrice
return new(big.Int).Mul(big.NewInt(int64(r.cfg.RedeemGas)), gasPrice)
}
Expand Down Expand Up @@ -286,7 +289,11 @@ func (r *recipient) TxCostMultiplier(sender ethcommon.Address) (*big.Rat, error)
// defaultTxCostMultiplier = defaultFaceValue / txCost
// Replacing defaultFaceValue with min(defaultFaceValue, MaxFloat(sender))
// Will scale the TxCostMultiplier according to the effective faceValue
return new(big.Rat).SetFrac(faceValue, r.txCost()), nil
txCost := r.txCost()
if txCost.Cmp(big.NewInt(0)) <= 0 {
return big.NewRat(0, 1), nil
}
return new(big.Rat).SetFrac(faceValue, txCost), nil
}

func (r *recipient) rand(seed *big.Int, sender ethcommon.Address, faceValue *big.Int, winProb *big.Int, expirationBlock *big.Int, price *big.Rat, ticketExpirationParams *TicketExpirationParams) *big.Int {
Expand Down
21 changes: 21 additions & 0 deletions pm/recipient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,27 @@ func TestTxCostMultiplier_InsufficientReserve_ReturnsError(t *testing.T) {
assert.EqualError(t, err, errInsufficientSenderReserve.Error())
}

func TestTxCostMultiplier_ZeroTxCost_Returns_Zero(t *testing.T) {
sender, b, v, gm, sm, tm, cfg, _ := newRecipientFixtureOrFatal(t)
gm.gasPrice = big.NewInt(0)
recipient := RandAddress()
secret := [32]byte{3}
r := NewRecipientWithSecret(recipient, b, v, gm, sm, tm, secret, cfg)

mul, err := r.TxCostMultiplier(sender)
assert.Nil(t, err)
assert.Equal(t, big.NewRat(0, 1), mul)
}

func TestTxCost_NilGasPrice_ReturnsZero(t *testing.T) {
_, b, v, gm, sm, tm, cfg, _ := newRecipientFixtureOrFatal(t)
gm.gasPrice = nil
secret := [32]byte{3}
r := NewRecipientWithSecret(RandAddress(), b, v, gm, sm, tm, secret, cfg)
txCost := r.(*recipient).txCost()
assert.Equal(t, big.NewInt(0), txCost)
}

func TestSenderNoncesCleanupLoop(t *testing.T) {
assert := assert.New(t)

Expand Down