From 0c15402f5c8d733577c48efe868b99c5acb58436 Mon Sep 17 00:00:00 2001 From: Nico Vergauwen Date: Wed, 7 Apr 2021 19:36:47 +0200 Subject: [PATCH 1/3] pm: add checks to allow gas price of 0 without panic --- pm/recipient.go | 11 +++++++++-- pm/recipient_test.go | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pm/recipient.go b/pm/recipient.go index eae5febdd0..80ac152ba9 100644 --- a/pm/recipient.go +++ b/pm/recipient.go @@ -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) } @@ -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 { diff --git a/pm/recipient_test.go b/pm/recipient_test.go index a92ec45100..b7ac2a57c9 100644 --- a/pm/recipient_test.go +++ b/pm/recipient_test.go @@ -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) From c7dd58e2c91fe7ada830263836751949f9e2007c Mon Sep 17 00:00:00 2001 From: Nico Vergauwen Date: Wed, 7 Apr 2021 19:38:01 +0200 Subject: [PATCH 2/3] core: allow a price overhead of 1 in case transaction cost is 0 --- core/orchestrator.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/orchestrator.go b/core/orchestrator.go index 93ca821669..3fa677f2aa 100644 --- a/core/orchestrator.go +++ b/core/orchestrator.go @@ -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)) From 5c439a9ddc84315d67076c074cebe198ce6a2c38 Mon Sep 17 00:00:00 2001 From: Nico Vergauwen Date: Wed, 7 Apr 2021 21:20:52 +0200 Subject: [PATCH 3/3] pending changelog entry --- CHANGELOG_PENDING.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index be6cc155fc..1dd605ef9a 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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) \ No newline at end of file