Skip to content

Commit

Permalink
add max face value to v0.5.29
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-astra-video committed Jun 18, 2022
1 parent d85cb21 commit e869fe6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func main() {
maxGasPrice := flag.Int("maxGasPrice", 0, "Maximum gas price (priority fee + base fee) for ETH transactions in wei, 40 Gwei = 40000000000")
ethController := flag.String("ethController", "", "Protocol smart contract address")
initializeRound := flag.Bool("initializeRound", false, "Set to true if running as a transcoder and the node should automatically initialize new rounds")
maxFaceValue := flag.String("maxFaceValue", "1000000000000", "The max faceValue for PM tickets")
ticketEV := flag.String("ticketEV", "1000000000000", "The expected value for PM tickets")
// Broadcaster max acceptable ticket EV
maxTicketEV := flag.String("maxTicketEV", "3000000000000", "The maximum acceptable expected value for PM tickets")
Expand Down Expand Up @@ -677,6 +678,19 @@ func main() {
timeWatcher,
cfg,
)
mfv, _ := new(big.Int).SetString(*maxFaceValue, 10)
if ev == nil {
panic(fmt.Errorf("-maxFaceValue must be a valid integer, but %v provided. Restart the node with a different valid value for -maxFaceValue", *maxFaceValue))
return
}

if ev.Cmp(big.NewInt(0)) < 0 {
panic(fmt.Errorf("-maxFaceValue must be greater than 0, but %v provided. Restart the node with a different valid value for -maxFaceValue", *maxFaceValue))
return
}
n.SetMaxFaceValue(mfv)
glog.Infof("Ticket max face value set to %v",*maxFaceValue)

if err != nil {
glog.Errorf("Error setting up PM recipient: %v", err)
return
Expand Down
1 change: 1 addition & 0 deletions cmd/livepeer_cli/livepeer_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (w *wizard) initializeOptions() []wizardOpt {
{desc: "Sign a message", invoke: w.signMessage},
{desc: "Sign typed data", invoke: w.signTypedData},
{desc: "Vote in a poll", invoke: w.vote, orchestrator: true},
{desc: "Set max ticket face value", invoke: w.setMaxFaceValue, orchestrator: true},
}
return options
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/livepeer_cli/wizard_transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ func (w *wizard) vote() {
fmt.Printf("\nVote success tx=0x%x\n", []byte(result))
}

func (w *wizard) setMaxFaceValue() {
fmt.Printf("Enter the max ticket face value in wei")
mfv := w.readBigInt()
data := url.Values{
"maxfacevalue": {fmt.Sprintf("%v", mfv.String())},
}
result, ok := httpPostWithParams(fmt.Sprintf("http://%v:%v/setMaxFaceValue", w.host, w.httpPort), data)
if ok {
fmt.Printf("Ticket max face value set")
return
} else {
fmt.Printf("Error setting max face value: %v", result)
return
}
}

func (w *wizard) showVoteChoices() {
wtr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(wtr, "Identifier\tVoting Choices")
Expand Down
8 changes: 8 additions & 0 deletions core/livepeernode.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ func (n *LivepeerNode) GetBasePrice() *big.Rat {
defer n.mu.RUnlock()
return n.priceInfo
}

// SetMaxFaceValue sets the faceValue upper limit for tickets received
func (n *LivepeerNode) SetMaxFaceValue(maxfacevalue *big.Int) {
n.mu.Lock()
defer n.mu.Unlock()

n.Recipient.SetMaxFaceValue(maxfacevalue)
}
19 changes: 17 additions & 2 deletions pm/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var paramsExpiryBuffer = int64(1)

var evMultiplier = big.NewInt(100)

// Hardcode to 200 gwei
// Hardcode to 1 gwei
// TODO: Replace this hardcoded value by dynamically determining the average gas price during a period of time
var avgGasPrice = new(big.Int).Mul(big.NewInt(200), new(big.Int).Exp(big.NewInt(10), big.NewInt(9), nil))
var avgGasPrice = new(big.Int).Mul(big.NewInt(1), new(big.Int).Exp(big.NewInt(10), big.NewInt(9), nil))

// Recipient is an interface which describes an object capable
// of receiving tickets
Expand All @@ -48,6 +48,9 @@ type Recipient interface {

// EV returns the recipients EV requirement for a ticket as configured on startup
EV() *big.Rat

//Set ticket faceValue upper limit
SetMaxFaceValue(maxfacevalue *big.Int)
}

// TicketParamsConfig contains config information for a recipient to determine
Expand Down Expand Up @@ -80,6 +83,7 @@ type recipient struct {

addr ethcommon.Address
secret [32]byte
maxfacevalue *big.Int

senderNonces map[string]*struct {
nonce uint32
Expand Down Expand Up @@ -118,6 +122,7 @@ func NewRecipientWithSecret(addr ethcommon.Address, broker Broker, val Validator
tm: tm,
addr: addr,
secret: secret,
maxfacevalue: big.NewInt(0),
senderNonces: make(map[string]*struct {
nonce uint32
expirationBlock *big.Int
Expand Down Expand Up @@ -256,6 +261,12 @@ func (r *recipient) faceValue(sender ethcommon.Address) (*big.Int, error) {
faceValue = maxFloat
}

if r.maxfacevalue.Cmp(big.NewInt(0)) > 0 {
if r.maxfacevalue.Cmp(faceValue) < 0 {
faceValue = r.maxfacevalue
}
}

if faceValue.Cmp(r.cfg.EV) < 0 {
return nil, errInsufficientSenderReserve
}
Expand Down Expand Up @@ -354,6 +365,10 @@ func (r *recipient) EV() *big.Rat {
return new(big.Rat).SetFrac(r.cfg.EV, big.NewInt(1))
}

func (r *recipient) SetMaxFaceValue(maxfacevalue *big.Int) {
r.maxfacevalue = maxfacevalue
}

func (r *recipient) senderNoncesCleanupLoop() {
sink := make(chan *big.Int, 10)
sub := r.tm.SubscribeL1Blocks(sink)
Expand Down
5 changes: 5 additions & 0 deletions pm/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ func (m *MockRecipient) EV() *big.Rat {
return args.Get(0).(*big.Rat)
}

// Sets the max ticket facevalue for the orchestrator
func (m *MockRecipient) SetMaxFaceValue(maxfacevalue *big.Int) {

}

// MockSender is useful for testing components that depend on pm.Sender
type MockSender struct {
mock.Mock
Expand Down
17 changes: 17 additions & 0 deletions server/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,23 @@ func (s *LivepeerServer) cliWebServerHandlers(bindAddr string) *http.ServeMux {
}

})

mux.HandleFunc("/setMaxFaceValue", func(w http.ResponseWriter, r *http.Request) {
if s.LivepeerNode.NodeType == core.OrchestratorNode {
maxfacevalue := r.FormValue("maxfacevalue")
if maxfacevalue != "" {
mfv, success := new(big.Int).SetString(maxfacevalue,10)
if success {
s.LivepeerNode.SetMaxFaceValue(mfv)
respondOk(w, []byte("ticket max face value set"))
} else {
respondWith400(w,"maxfacevalue not set to number")
}
} else {
respondWith400(w, "need to set 'maxfacevalue'")
}
}
})

//Bond some amount of tokens to an orchestrator.
mux.HandleFunc("/bond", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit e869fe6

Please sign in to comment.