Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVM: Expose relevant incentive constants #6025

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,12 @@ func lines(s string, num int) (bool, string) {
}

func summarize(trace *strings.Builder) string {
truncated, msg := lines(trace.String(), 50)
jannotti marked this conversation as resolved.
Show resolved Hide resolved
if !truncated {
return msg
all := trace.String()
if strings.Count(all, "\n") < 50 {
return all
}
return msg + "(trace truncated)\n"
lines := strings.Split(trace.String(), "\n")
return strings.Join(lines[:20], "\n") + "\n(some trace elided)\n" + strings.Join(lines[len(lines)-20:], "\n")
}

func testProg(t testing.TB, source string, ver uint64, expected ...expect) *OpStream {
Expand Down Expand Up @@ -1713,6 +1714,11 @@ pushint 1
block BlkFeesCollected
pushint 1
block BlkBonus
global PayoutsEnabled
global PayoutsGoOnlineFee
global PayoutsPercent
global PayoutsMinBalance
global PayoutsMaxBalance
`, AssemblerMaxVersion)
for _, names := range [][]string{GlobalFieldNames[:], TxnFieldNames[:], blockFieldNames[:]} {
for _, f := range names {
Expand Down
10 changes: 10 additions & 0 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -3732,6 +3732,16 @@ func (cx *EvalContext) globalFieldToValue(fs globalFieldSpec) (sv stackValue, er
case GenesisHash:
gh := cx.SigLedger.GenesisHash()
sv.Bytes = gh[:]
case PayoutsEnabled:
sv.Uint = boolToUint(cx.Proto.Payouts.Enabled)
case PayoutsGoOnlineFee:
sv.Uint = cx.Proto.Payouts.GoOnlineFee
case PayoutsPercent:
sv.Uint = cx.Proto.Payouts.Percent
case PayoutsMinBalance:
sv.Uint = cx.Proto.Payouts.MinBalance
case PayoutsMaxBalance:
sv.Uint = cx.Proto.Payouts.MaxBalance
default:
return sv, fmt.Errorf("invalid global field %s", fs.field)
}
Expand Down
16 changes: 14 additions & 2 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func makeTestProto(opts ...protoOpt) *config.ConsensusParams {

MaxBoxSize: 1000,
BytesPerBoxReference: 100,

Payouts: config.ProposerPayoutRules{
Enabled: true,
GoOnlineFee: 3,
Percent: 4,
MinBalance: 5,
MaxBalance: 6,
},
}
for _, opt := range opts {
if opt != nil { // so some callsites can take one arg and pass it in
Expand Down Expand Up @@ -1236,7 +1244,11 @@ global GenesisHash; len; int 32; ==; &&
`

const globalV11TestProgram = globalV10TestProgram + `
// No new globals in v11
global PayoutsEnabled; assert
global PayoutsGoOnlineFee; int 3; ==; assert
global PayoutsPercent; int 4; ==; assert
global PayoutsMinBalance; int 5; ==; assert
global PayoutsMaxBalance; int 6; ==; assert
`

func TestGlobal(t *testing.T) {
Expand All @@ -1260,7 +1272,7 @@ func TestGlobal(t *testing.T) {
8: {CallerApplicationAddress, globalV8TestProgram},
9: {CallerApplicationAddress, globalV9TestProgram},
10: {GenesisHash, globalV10TestProgram},
11: {GenesisHash, globalV11TestProgram},
11: {PayoutsMaxBalance, globalV11TestProgram},
}
// tests keys are versions so they must be in a range 1..AssemblerMaxVersion plus zero version
require.LessOrEqual(t, len(tests), AssemblerMaxVersion+1)
Expand Down
26 changes: 26 additions & 0 deletions data/transactions/logic/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,21 @@ const (
// GenesisHash is the genesis hash for the network
GenesisHash

// PayoutsEnabled is whether block proposal payouts are enabled
PayoutsEnabled

// PayoutsGoOnlineFee is the fee required in a keyreg transaction to make an account incentive eligible
PayoutsGoOnlineFee

// PayoutsPercent is the percentage of transaction fees in a block that can be paid to the block proposer.
PayoutsPercent

// PayoutsMinBalance is the minimum algo balance an account must have to receive block payouts (in the agreement round).
PayoutsMinBalance

// PayoutsMaxBalance is the minimum algo balance an account must have to receive block payouts (in the agreement round).
jannotti marked this conversation as resolved.
Show resolved Hide resolved
PayoutsMaxBalance

invalidGlobalField // compile-time constant for number of fields
)

Expand Down Expand Up @@ -603,6 +618,17 @@ var globalFieldSpecs = [...]globalFieldSpec{
{AssetOptInMinBalance, StackUint64, modeAny, 10,
"The additional minimum balance required to opt-in to an asset."},
{GenesisHash, StackBytes32, modeAny, 10, "The Genesis Hash for the network."},

{PayoutsEnabled, StackBoolean, modeAny, incentiveVersion,
gmalouf marked this conversation as resolved.
Show resolved Hide resolved
"Whether block proposal payouts are enabled."},
{PayoutsGoOnlineFee, StackUint64, modeAny, incentiveVersion,
"The fee required in a keyreg transaction to make an account incentive eligible."},
{PayoutsPercent, StackUint64, modeAny, incentiveVersion,
"The percentage of transaction fees in a block that can be paid to the block proposer."},
{PayoutsMinBalance, StackUint64, modeAny, incentiveVersion,
"The minimum algo balance an account must have in the agreement round to receive block payouts in the proposal round."},
{PayoutsMaxBalance, StackUint64, modeAny, incentiveVersion,
"The minimum algo balance an account must have in the agreement round to receive block payouts in the proposal round."},
jannotti marked this conversation as resolved.
Show resolved Hide resolved
}

func globalFieldSpecByField(f GlobalField) (globalFieldSpec, bool) {
Expand Down
11 changes: 8 additions & 3 deletions data/transactions/logic/fields_string.go

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

Loading