Skip to content

Commit

Permalink
Add in the actual heartbeat crypto, simple test of the service
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Oct 21, 2024
1 parent c2c7262 commit 936b219
Show file tree
Hide file tree
Showing 16 changed files with 589 additions and 214 deletions.
9 changes: 7 additions & 2 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ type ConsensusParams struct {
// occur, extra funds need to be put into the FeeSink. The bonus amount
// decays exponentially.
Bonus BonusPlan

// Heartbeat support
Heartbeat bool
}

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

vFuture.Payouts.Enabled = true
vFuture.Payouts.Percent = 75
vFuture.Payouts.Percent = 50
vFuture.Payouts.GoOnlineFee = 2_000_000 // 2 algos
vFuture.Payouts.MinBalance = 30_000_000_000 // 30,000 algos
vFuture.Payouts.MaxBalance = 70_000_000_000_000 // 70M algos
Expand All @@ -1524,7 +1527,9 @@ func initConsensusProtocols() {

vFuture.Bonus.BaseAmount = 10_000_000 // 10 Algos
// 2.9 sec rounds gives about 10.8M rounds per year.
vFuture.Bonus.DecayInterval = 250_000 // .99^(10.8/0.25) ~ .648. So 35% decay per year
vFuture.Bonus.DecayInterval = 1_000_000 // .99^(10.8M/1M) ~ .897. So ~10% decay per year

vFuture.Heartbeat = true

Consensus[protocol.ConsensusFuture] = vFuture

Expand Down
8 changes: 4 additions & 4 deletions data/committee/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type selectionParameterListFn func(addr []basics.Address) (bool, []BalanceRecord

var proto = config.Consensus[protocol.ConsensusCurrentVersion]

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

func testingenvMoreKeys(t testing.TB, numAccounts, numTxs int, keyBatchesForward uint, seedGen io.Reader) (selectionParameterFn, selectionParameterListFn, basics.Round, []basics.Address, []*crypto.SignatureSecrets, []*crypto.VrfPrivkey) {
func testingenvMoreKeys(t testing.TB, numAccounts, numTxs int, seedGen io.Reader) (selectionParameterFn, selectionParameterListFn, basics.Round, []basics.Address, []*crypto.SignatureSecrets, []*crypto.VrfPrivkey) {
if seedGen == nil {
seedGen = rand.New(rand.NewSource(1)) // same source as setting GODEBUG=randautoseed=0, same as pre-Go 1.20 default seed
}
Expand All @@ -70,7 +70,7 @@ func testingenvMoreKeys(t testing.TB, numAccounts, numTxs int, keyBatchesForward
lookback := basics.Round(2*proto.SeedRefreshInterval + proto.SeedLookback + 1)
var total basics.MicroAlgos
for i := 0; i < P; i++ {
addr, sigSec, vrfSec := newAccount(t, gen, lookback, keyBatchesForward)
addr, sigSec, vrfSec := newAccount(t, gen)
addrs[i] = addr
secrets[i] = sigSec
vrfSecrets[i] = vrfSec
Expand Down
3 changes: 1 addition & 2 deletions data/committee/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ func TestNoMoneyAccountNotSelected(t *testing.T) {
N := 1
for i := 0; i < N; i++ {
selParams, _, round, addresses, _, _ := testingenv(t, 10, 2000, seedGen)
lookback := basics.Round(2*proto.SeedRefreshInterval + proto.SeedLookback + 1)
gen := rand.New(rand.NewSource(2))
_, _, zeroVRFSecret := newAccount(t, gen, lookback, 5)
_, _, zeroVRFSecret := newAccount(t, gen)
period := Period(0)
ok, record, selectionSeed, _ := selParams(addresses[i])
if !ok {
Expand Down
10 changes: 5 additions & 5 deletions data/transactions/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ type HeartbeatTxnFields struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

// HeartbeatAddress is the account this txn is proving onlineness for.
HeartbeatAddress basics.Address `codec:"hbad"`
HbAddress basics.Address `codec:"hbad"`

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

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

0 comments on commit 936b219

Please sign in to comment.