Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased Changes

- [#3275](https://github.com/livepeer/go-livepeer/pull/3275) - Provide AI orchestrators with a way to vote on active proposal through the CLI.

## v0.X.X

### Breaking Changes 🚨🚨
Expand Down
3 changes: 2 additions & 1 deletion cmd/livepeer_cli/livepeer_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ func (w *wizard) initializeOptions() []wizardOpt {
}, testnet: true},
{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: "Vote in a governance poll", invoke: w.vote, orchestrator: true},
{desc: "Vote on a treasury proposal", invoke: w.voteOnProposal, orchestrator: true},
{desc: "Set max ticket face value", invoke: w.setMaxFaceValue, orchestrator: true},
{desc: "Set price for broadcaster", invoke: w.setPriceForBroadcaster, orchestrator: true},
{desc: "Set maximum sessions", invoke: w.setMaxSessions, orchestrator: true, notOrchestrator: false},
Expand Down
67 changes: 67 additions & 0 deletions cmd/livepeer_cli/wizard_transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,64 @@
fmt.Printf("\nVote success tx=0x%x\n", []byte(result))
}

func (w *wizard) voteOnProposal() {
if w.offchain {
glog.Error("Cannot vote in 'offchain' mode")
return
}

Check warning on line 285 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L281-L285

Added lines #L281 - L285 were not covered by tests

fmt.Print("Enter the proposal ID you want to vote on -")
proposalID := w.readStringAndValidate(func(in string) (string, error) {
if _, ok := new(big.Int).SetString(in, 10); !ok {
return "", fmt.Errorf("invalid proposal ID id=%v", in)
}
return in, nil

Check warning on line 292 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L287-L292

Added lines #L287 - L292 were not covered by tests
})

var (
confirm = "n"
choice = types.ProposalVoteChoice(-1)
)

for confirm == "n" {
w.showProposalVoteChoices()

for {
fmt.Printf("Enter the ID of the choice you want to vote for -")
choice = types.ProposalVoteChoice(w.readInt())
if choice.IsValid() {
break

Check warning on line 307 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L295-L307

Added lines #L295 - L307 were not covered by tests
}
fmt.Println("Must enter a valid ID")

Check warning on line 309 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L309

Added line #L309 was not covered by tests
}

fmt.Printf("Are you sure you want to vote \"%v\"? (y/n) -", choice.String())
confirm = w.readStringYesOrNo()

Check warning on line 313 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L312-L313

Added lines #L312 - L313 were not covered by tests
}

fmt.Printf("Do you want to provide a reason for your vote? (y/n) -")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be awesome to display these in the dashboard at some point!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mike will be adding it to his vote tracker. At the moment it is just me and Titan setting the reason, but with this PR we might see a lot more Orchestrators add a reason to their vote.

provideReason := w.readStringYesOrNo()
var reason string
if provideReason == "y" {
fmt.Print("Enter your reason -")
reason = w.readString()
}

Check warning on line 322 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L316-L322

Added lines #L316 - L322 were not covered by tests

data := url.Values{
"proposalID": {proposalID},
"support": {fmt.Sprintf("%v", int(choice))},
"reason": {reason},
}

result, ok := httpPostWithParams(fmt.Sprintf("http://%v:%v/voteOnProposal", w.host, w.httpPort), data)

if !ok {
fmt.Printf("Error voting: %s\n", result)
return
}
fmt.Printf("\nVote success tx=0x%x\n", []byte(result))

Check warning on line 336 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L324-L336

Added lines #L324 - L336 were not covered by tests
}

func (w *wizard) showVoteChoices() {
wtr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(wtr, "Identifier\tVoting Choices")
Expand All @@ -287,6 +345,15 @@
wtr.Flush()
}

func (w *wizard) showProposalVoteChoices() {
wtr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(wtr, "Identifier\tVoting Choices")
for _, choice := range types.ProposalVoteChoices {
fmt.Fprintf(wtr, "%v\t%v\n", int(choice), choice.String())
}
wtr.Flush()

Check warning on line 354 in cmd/livepeer_cli/wizard_transcoder.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer_cli/wizard_transcoder.go#L348-L354

Added lines #L348 - L354 were not covered by tests
}

func flipPerc(perc *big.Int) *big.Int {
return new(big.Int).Sub(hundredPercent, perc)
}
Expand Down
48 changes: 39 additions & 9 deletions eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//go:generate abigen --abi protocol/abi/Minter.json --pkg contracts --type Minter --out contracts/minter.go
//go:generate abigen --abi protocol/abi/LivepeerTokenFaucet.json --pkg contracts --type LivepeerTokenFaucet --out contracts/livepeerTokenFaucet.go
//go:generate abigen --abi protocol/abi/Poll.json --pkg contracts --type Poll --out contracts/poll.go
//go:generate abigen --abi protocol/abi/LivepeerGovernor.json --pkg contracts --type Governor --out contracts/LivepeerGovernor.go
import (
"context"
"fmt"
Expand Down Expand Up @@ -113,6 +114,8 @@

// Governance
Vote(ethcommon.Address, *big.Int) (*types.Transaction, error)
ProposalVote(*big.Int, uint8) (*types.Transaction, error)
ProposalVoteWithReason(*big.Int, uint8, string) (*types.Transaction, error)

// Helpers
ContractAddresses() map[string]ethcommon.Address
Expand All @@ -130,15 +133,16 @@
transOpts bind.TransactOpts
transOptsMu sync.RWMutex

controllerAddr ethcommon.Address
tokenAddr ethcommon.Address
serviceRegistryAddr ethcommon.Address
bondingManagerAddr ethcommon.Address
ticketBrokerAddr ethcommon.Address
roundsManagerAddr ethcommon.Address
minterAddr ethcommon.Address
verifierAddr ethcommon.Address
faucetAddr ethcommon.Address
controllerAddr ethcommon.Address
tokenAddr ethcommon.Address
serviceRegistryAddr ethcommon.Address
bondingManagerAddr ethcommon.Address
ticketBrokerAddr ethcommon.Address
roundsManagerAddr ethcommon.Address
minterAddr ethcommon.Address
verifierAddr ethcommon.Address
faucetAddr ethcommon.Address
livepeerGovernorAddr ethcommon.Address

// Contracts
controller *contracts.Controller
Expand All @@ -149,6 +153,7 @@
roundsManager *contracts.RoundsManager
minter *contracts.Minter
livepeerTokenFaucet *contracts.LivepeerTokenFaucet
livepeerGovernor *contracts.Governor

// for L1 contracts backwards-compatibility
l1BondingManager *contracts.L1BondingManager
Expand Down Expand Up @@ -325,6 +330,23 @@

glog.V(common.SHORT).Infof("LivepeerTokenFaucet: %v", c.faucetAddr.Hex())

livepeerGovernorAddr, err := c.GetContract(crypto.Keccak256Hash([]byte("LivepeerGovernor")))
if err != nil {
glog.Errorf("Error getting Governor address: %v", err)
return err
}

Check warning on line 337 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L333-L337

Added lines #L333 - L337 were not covered by tests

c.livepeerGovernorAddr = livepeerGovernorAddr

governor, err := contracts.NewGovernor(livepeerGovernorAddr, c.backend)
if err != nil {
glog.Errorf("Error creating Governor binding: %v", err)
return err
}
c.livepeerGovernor = governor

glog.V(common.SHORT).Infof("LivepeerGovernor: %v", c.livepeerGovernorAddr.Hex())

Check warning on line 349 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L339-L349

Added lines #L339 - L349 were not covered by tests
return nil
}

Expand Down Expand Up @@ -990,6 +1012,14 @@
return poll.Vote(opts, choiceID)
}

func (c *client) ProposalVote(proposalId *big.Int, support uint8) (*types.Transaction, error) {
return c.livepeerGovernor.CastVote(c.transactOpts(), proposalId, support)

Check warning on line 1016 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L1015-L1016

Added lines #L1015 - L1016 were not covered by tests
}

func (c *client) ProposalVoteWithReason(proposalId *big.Int, support uint8, reason string) (*types.Transaction, error) {
return c.livepeerGovernor.CastVoteWithReason(c.transactOpts(), proposalId, support, reason)

Check warning on line 1020 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L1019-L1020

Added lines #L1019 - L1020 were not covered by tests
}

func (c *client) Reward() (*types.Transaction, error) {
addr := c.accountManager.Account().Address

Expand Down
3,745 changes: 3,745 additions & 0 deletions eth/contracts/LivepeerGovernor.go

Large diffs are not rendered by default.

465 changes: 462 additions & 3 deletions eth/contracts/bondingManager.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions eth/contracts/controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

944 changes: 752 additions & 192 deletions eth/contracts/livepeerToken.go

Large diffs are not rendered by default.

Loading
Loading