Skip to content

Commit ada8222

Browse files
committed
Add in the actual heartbeat crypto, simple test of the service
1 parent c2c7262 commit ada8222

18 files changed

+604
-229
lines changed

config/consensus.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ type ConsensusParams struct {
540540
// occur, extra funds need to be put into the FeeSink. The bonus amount
541541
// decays exponentially.
542542
Bonus BonusPlan
543+
544+
// Heartbeat support
545+
Heartbeat bool
543546
}
544547

545548
// ProposerPayoutRules puts several related consensus parameters in one place. The same
@@ -1513,7 +1516,7 @@ func initConsensusProtocols() {
15131516
vFuture.LogicSigVersion = 11 // When moving this to a release, put a new higher LogicSigVersion here
15141517

15151518
vFuture.Payouts.Enabled = true
1516-
vFuture.Payouts.Percent = 75
1519+
vFuture.Payouts.Percent = 50
15171520
vFuture.Payouts.GoOnlineFee = 2_000_000 // 2 algos
15181521
vFuture.Payouts.MinBalance = 30_000_000_000 // 30,000 algos
15191522
vFuture.Payouts.MaxBalance = 70_000_000_000_000 // 70M algos
@@ -1524,7 +1527,9 @@ func initConsensusProtocols() {
15241527

15251528
vFuture.Bonus.BaseAmount = 10_000_000 // 10 Algos
15261529
// 2.9 sec rounds gives about 10.8M rounds per year.
1527-
vFuture.Bonus.DecayInterval = 250_000 // .99^(10.8/0.25) ~ .648. So 35% decay per year
1530+
vFuture.Bonus.DecayInterval = 1_000_000 // .99^(10.8M/1M) ~ .897. So ~10% decay per year
1531+
1532+
vFuture.Heartbeat = true
15281533

15291534
Consensus[protocol.ConsensusFuture] = vFuture
15301535

data/bookkeeping/block_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,11 @@ func TestFirstYearsBonus(t *testing.T) {
10131013
fmt.Printf("paid %d algos\n", suma)
10141014
fmt.Printf("bonus start: %d end: %d\n", plan.BaseAmount, bonus)
10151015

1016-
// pays about 88M algos
1017-
a.InDelta(88_500_000, suma, 100_000)
1016+
// pays about 103.5M algos
1017+
a.InDelta(103_500_000, suma, 100_000)
10181018

1019-
// decline about 35%
1020-
a.InDelta(0.65, float64(bonus)/float64(plan.BaseAmount), 0.01)
1019+
// decline about 10%
1020+
a.InDelta(0.90, float64(bonus)/float64(plan.BaseAmount), 0.01)
10211021

10221022
// year 2
10231023
for i := 0; i < yearRounds; i++ {
@@ -1033,11 +1033,11 @@ func TestFirstYearsBonus(t *testing.T) {
10331033
fmt.Printf("paid %d algos after 2 years\n", sum2)
10341034
fmt.Printf("bonus end: %d\n", bonus)
10351035

1036-
// pays about 146M algos (total for 2 years)
1037-
a.InDelta(145_700_000, sum2, 100_000)
1036+
// pays about 196M algos (total for 2 years)
1037+
a.InDelta(196_300_000, sum2, 100_000)
10381038

1039-
// decline about 58%
1040-
a.InDelta(0.42, float64(bonus)/float64(plan.BaseAmount), 0.01)
1039+
// decline to about 81%
1040+
a.InDelta(0.81, float64(bonus)/float64(plan.BaseAmount), 0.01)
10411041

10421042
// year 3
10431043
for i := 0; i < yearRounds; i++ {
@@ -1053,9 +1053,9 @@ func TestFirstYearsBonus(t *testing.T) {
10531053
fmt.Printf("paid %d algos after 3 years\n", sum3)
10541054
fmt.Printf("bonus end: %d\n", bonus)
10551055

1056-
// pays about 182M algos (total for 3 years)
1057-
a.InDelta(182_600_000, sum3, 100_000)
1056+
// pays about 279M algos (total for 3 years)
1057+
a.InDelta(279_500_000, sum3, 100_000)
10581058

1059-
// declined to about 27% (but foundation funding probably gone anyway)
1060-
a.InDelta(0.27, float64(bonus)/float64(plan.BaseAmount), 0.01)
1059+
// declined to about 72% (but foundation funding probably gone anyway)
1060+
a.InDelta(0.72, float64(bonus)/float64(plan.BaseAmount), 0.01)
10611061
}

data/committee/common_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type selectionParameterListFn func(addr []basics.Address) (bool, []BalanceRecord
3232

3333
var proto = config.Consensus[protocol.ConsensusCurrentVersion]
3434

35-
func newAccount(t testing.TB, gen io.Reader, latest basics.Round, keyBatchesForward uint) (basics.Address, *crypto.SignatureSecrets, *crypto.VrfPrivkey) {
35+
func newAccount(t testing.TB, gen io.Reader) (basics.Address, *crypto.SignatureSecrets, *crypto.VrfPrivkey) {
3636
var seed crypto.Seed
3737
gen.Read(seed[:])
3838
s := crypto.GenerateSignatureSecrets(seed)
@@ -49,10 +49,10 @@ func newAccount(t testing.TB, gen io.Reader, latest basics.Round, keyBatchesForw
4949
// formerly, testingenv, generated transactions and one-time secrets as well,
5050
// but they were not used by the tests.
5151
func testingenv(t testing.TB, numAccounts, numTxs int, seedGen io.Reader) (selectionParameterFn, selectionParameterListFn, basics.Round, []basics.Address, []*crypto.SignatureSecrets, []*crypto.VrfPrivkey) {
52-
return testingenvMoreKeys(t, numAccounts, numTxs, uint(5), seedGen)
52+
return testingenvMoreKeys(t, numAccounts, numTxs, seedGen)
5353
}
5454

55-
func testingenvMoreKeys(t testing.TB, numAccounts, numTxs int, keyBatchesForward uint, seedGen io.Reader) (selectionParameterFn, selectionParameterListFn, basics.Round, []basics.Address, []*crypto.SignatureSecrets, []*crypto.VrfPrivkey) {
55+
func testingenvMoreKeys(t testing.TB, numAccounts, numTxs int, seedGen io.Reader) (selectionParameterFn, selectionParameterListFn, basics.Round, []basics.Address, []*crypto.SignatureSecrets, []*crypto.VrfPrivkey) {
5656
if seedGen == nil {
5757
seedGen = rand.New(rand.NewSource(1)) // same source as setting GODEBUG=randautoseed=0, same as pre-Go 1.20 default seed
5858
}
@@ -70,7 +70,7 @@ func testingenvMoreKeys(t testing.TB, numAccounts, numTxs int, keyBatchesForward
7070
lookback := basics.Round(2*proto.SeedRefreshInterval + proto.SeedLookback + 1)
7171
var total basics.MicroAlgos
7272
for i := 0; i < P; i++ {
73-
addr, sigSec, vrfSec := newAccount(t, gen, lookback, keyBatchesForward)
73+
addr, sigSec, vrfSec := newAccount(t, gen)
7474
addrs[i] = addr
7575
secrets[i] = sigSec
7676
vrfSecrets[i] = vrfSec

data/committee/credential_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,8 @@ func TestNoMoneyAccountNotSelected(t *testing.T) {
251251
N := 1
252252
for i := 0; i < N; i++ {
253253
selParams, _, round, addresses, _, _ := testingenv(t, 10, 2000, seedGen)
254-
lookback := basics.Round(2*proto.SeedRefreshInterval + proto.SeedLookback + 1)
255254
gen := rand.New(rand.NewSource(2))
256-
_, _, zeroVRFSecret := newAccount(t, gen, lookback, 5)
255+
_, _, zeroVRFSecret := newAccount(t, gen)
257256
period := Period(0)
258257
ok, record, selectionSeed, _ := selParams(addresses[i])
259258
if !ok {

data/transactions/heartbeat.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ type HeartbeatTxnFields struct {
2929
_struct struct{} `codec:",omitempty,omitemptyarray"`
3030

3131
// HeartbeatAddress is the account this txn is proving onlineness for.
32-
HeartbeatAddress basics.Address `codec:"hbad"`
32+
HbAddress basics.Address `codec:"hbad"`
3333

34-
// Proof is a signature using HeartbeatAddress's partkey, thereby showing it is online.
35-
Proof crypto.OneTimeSignature `codec:"hbprf"`
34+
// HbProof is a signature using HeartbeatAddress's partkey, thereby showing it is online.
35+
HbProof crypto.OneTimeSignature `codec:"hbprf"`
3636

37-
// Seed must be the block seed for the block before this transaction's
37+
// HbSeed must be the block seed for the block before this transaction's
3838
// firstValid. It is supplied in the transaction so that Proof can be
3939
// checked at submit time without a ledger lookup, and must be checked at
4040
// evaluation time for equality with the actual blockseed.
41-
Seed committee.Seed `codec:"hbsd"`
41+
HbSeed committee.Seed `codec:"hbsd"`
4242
}

0 commit comments

Comments
 (0)