Skip to content

Commit

Permalink
Merge pull request livepeer#1219 from livepeer/nv/orchwatcher-serviceuri
Browse files Browse the repository at this point in the history
eth/watchers: store serviceURI on TranscoderActivated event
  • Loading branch information
kyriediculous authored Nov 27, 2019
2 parents a18f2b1 + 0f6d907 commit 23143c7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion eth/stubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type StubClient struct {
ClaimedAmount *big.Int
ClaimedReserveError error
Orch *lpTypes.Transcoder
Err error
}

type stubTranscoder struct {
Expand Down Expand Up @@ -204,7 +205,12 @@ func (e *StubClient) TotalSupply() (*big.Int, error) { return b
// Service Registry

func (e *StubClient) SetServiceURI(serviceURI string) (*types.Transaction, error) { return nil, nil }
func (e *StubClient) GetServiceURI(addr common.Address) (string, error) { return e.Orch.ServiceURI, nil }
func (e *StubClient) GetServiceURI(addr common.Address) (string, error) {
if e.Err != nil {
return "", e.Err
}
return e.Orch.ServiceURI, nil
}

// Staking

Expand All @@ -228,6 +234,9 @@ func (e *StubClient) ClaimEarnings(endRound *big.Int) error {
return nil
}
func (e *StubClient) GetTranscoder(addr common.Address) (*lpTypes.Transcoder, error) {
if e.Err != nil {
return nil, e.Err
}
return e.Orch, nil
}
func (e *StubClient) GetDelegator(addr common.Address) (*lpTypes.Delegator, error) { return nil, nil }
Expand Down
7 changes: 7 additions & 0 deletions eth/watchers/orchestratorwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ func (ow *OrchestratorWatcher) handleTranscoderActivated(log types.Log) error {
}

if !log.Removed {
uri, err := ow.lpEth.GetServiceURI(transcoderActivated.Transcoder)
if err != nil {
return err
}

return ow.store.UpdateOrch(
&common.DBOrch{
EthereumAddr: transcoderActivated.Transcoder.String(),
ServiceURI: uri,
ActivationRound: transcoderActivated.ActivationRound.Int64(),
DeactivationRound: maxFutureRound,
},
Expand All @@ -112,6 +118,7 @@ func (ow *OrchestratorWatcher) handleTranscoderActivated(log types.Log) error {
return ow.store.UpdateOrch(
&common.DBOrch{
EthereumAddr: t.Address.String(),
ServiceURI: t.ServiceURI,
ActivationRound: t.ActivationRound.Int64(),
DeactivationRound: t.DeactivationRound.Int64(),
},
Expand Down
24 changes: 24 additions & 0 deletions eth/watchers/orchestratorwatcher_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package watchers

import (
"errors"
"math/big"
"testing"
"time"

"github.com/golang/glog"
"github.com/livepeer/go-livepeer/eth"
"github.com/livepeer/go-livepeer/eth/blockwatch"
lpTypes "github.com/livepeer/go-livepeer/eth/types"
Expand Down Expand Up @@ -38,6 +40,7 @@ func TestOrchWatcher_HandleLog_TranscoderActivated(t *testing.T) {
Address: pm.RandAddress(),
ActivationRound: big.NewInt(5),
DeactivationRound: big.NewInt(100),
ServiceURI: "http://mytranscoder.lpt:1337",
},
}
ow, err := NewOrchestratorWatcher(stubBondingManagerAddr, watcher, stubStore, lpEth)
Expand All @@ -60,13 +63,34 @@ func TestOrchWatcher_HandleLog_TranscoderActivated(t *testing.T) {
assert.Equal(stubActivationRound.Int64(), stubStore.activationRound)
assert.Equal(stubStore.deactivationRound, maxFutureRound)
assert.Equal(stubStore.ethereumAddr, stubTranscoder.String())
assert.Equal(stubStore.serviceURI, "http://mytranscoder.lpt:1337")

// test GetServiceURI error
errorLogsBefore := glog.Stats.Error.Lines()
lpEth.Err = errors.New("GetServiceURI error")
watcher.sink <- []*blockwatch.Event{blockEvent}
time.Sleep(2 * time.Millisecond)
errorLogsAfter := glog.Stats.Error.Lines()
assert.Equal(int64(1), errorLogsAfter-errorLogsBefore)
lpEth.Err = nil

blockEvent.Type = blockwatch.Removed
lpEth.Orch.ServiceURI = "http://mytranscoder.lpt:0000"
watcher.sink <- []*blockwatch.Event{blockEvent}
time.Sleep(2 * time.Millisecond)
assert.Equal(stubStore.activationRound, int64(5))
assert.Equal(stubStore.deactivationRound, int64(100))
assert.Equal(stubStore.ethereumAddr, lpEth.Orch.Address.String())
assert.Equal(stubStore.serviceURI, "http://mytranscoder.lpt:0000")

// test GetTranscoder error
errorLogsBefore = glog.Stats.Error.Lines()
lpEth.Err = errors.New("GetTranscoder error")
watcher.sink <- []*blockwatch.Event{blockEvent}
time.Sleep(2 * time.Millisecond)
errorLogsAfter = glog.Stats.Error.Lines()
assert.Equal(int64(1), errorLogsAfter-errorLogsBefore)
lpEth.Err = nil
}

func TestOrchWatcher_HandleLog_TranscoderDeactivated(t *testing.T) {
Expand Down

0 comments on commit 23143c7

Please sign in to comment.