Skip to content

Commit

Permalink
Merge pull request livepeer#1237 from livepeer/nv/max-deactivationround
Browse files Browse the repository at this point in the history
discovery: use maxInt64 deactivationRound in cacheTranscoderPool
  • Loading branch information
kyriediculous authored Dec 3, 2019
2 parents 09f3589 + 0229c64 commit 517ea8a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion discovery/db_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package discovery
import (
"context"
"fmt"
"math"
"math/big"
"net/url"
"strings"
Expand All @@ -20,6 +21,8 @@ import (
"github.com/golang/glog"
)

const maxInt64 = int64(math.MaxInt64)

var cacheRefreshInterval = 1 * time.Hour
var getTicker = func() *time.Ticker {
return time.NewTicker(cacheRefreshInterval)
Expand Down Expand Up @@ -243,12 +246,18 @@ func ethOrchToDBOrch(orch *lpTypes.Transcoder) *common.DBOrch {
return nil
}

return &common.DBOrch{
dbo := &common.DBOrch{
ServiceURI: orch.ServiceURI,
EthereumAddr: orch.Address.String(),
ActivationRound: orch.ActivationRound.Int64(),
DeactivationRound: orch.DeactivationRound.Int64(),
}

if orch.DeactivationRound.Cmp(big.NewInt(maxInt64)) == 1 {
dbo.DeactivationRound = maxInt64
}

return dbo
}

func pmTicketParams(params *net.TicketParams) *pm.TicketParams {
Expand Down
27 changes: 27 additions & 0 deletions discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"testing"
"time"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/golang/glog"
"github.com/livepeer/go-livepeer/common"
"github.com/livepeer/go-livepeer/core"
"github.com/livepeer/go-livepeer/eth"
lpTypes "github.com/livepeer/go-livepeer/eth/types"
"github.com/livepeer/go-livepeer/net"
"github.com/livepeer/go-livepeer/pm"
"github.com/livepeer/go-livepeer/server"
Expand Down Expand Up @@ -1078,3 +1080,28 @@ func TestDeserializeWebhookJSON(t *testing.T) {
assert.Contains(err.Error(), "cannot unmarshal number")
assert.Empty(urls)
}

func TestEthOrchToDBOrch(t *testing.T) {
assert := assert.New(t)
o := &lpTypes.Transcoder{
ServiceURI: "hello livepeer",
ActivationRound: big.NewInt(5),
DeactivationRound: big.NewInt(100),
Address: ethcommon.HexToAddress("0x79f709b01033dfDBf065cfF7a1Abe7C72011D3EB"),
}

dbo := ethOrchToDBOrch(o)

assert.Equal(dbo.ServiceURI, o.ServiceURI)
assert.Equal(dbo.EthereumAddr, o.Address.Hex())
assert.Equal(dbo.ActivationRound, o.ActivationRound.Int64())
assert.Equal(dbo.DeactivationRound, o.DeactivationRound.Int64())

// If DeactivationRound > maxInt64 => DeactivationRound = maxInt64
o.DeactivationRound, _ = new(big.Int).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10)
dbo = ethOrchToDBOrch(o)
assert.Equal(dbo.ServiceURI, o.ServiceURI)
assert.Equal(dbo.EthereumAddr, o.Address.Hex())
assert.Equal(dbo.ActivationRound, o.ActivationRound.Int64())
assert.Equal(dbo.DeactivationRound, maxInt64)
}

0 comments on commit 517ea8a

Please sign in to comment.