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

Incentives: Add heartbeat address to txn_participation (making search eligible) #1642

Merged
merged 1 commit into from
Jan 2, 2025
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
Binary file not shown.
2 changes: 2 additions & 0 deletions idb/postgres/internal/writer/write_txn_participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func addTransactionParticipants(stxnad *types.SignedTxnWithAD, includeInner bool
for _, address := range txn.ApplicationCallTxnFields.Accounts {
add(address)
}
case types.HeartbeatTx:
add(txn.HbAddress)
}

if includeInner {
Expand Down
67 changes: 62 additions & 5 deletions idb/postgres/internal/writer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ func TestWriterTxnParticipationTableNoPayout(t *testing.T) {
tests = append(tests, testcase)
}
{
stxnad := test.MakeCreateAppTxn(sdk.Address(test.AccountA))
stxnad := test.MakeCreateAppTxn(test.AccountA)
stxnad.Txn.ApplicationCallTxnFields.Accounts =
[]sdk.Address{sdk.Address(test.AccountB), sdk.Address(test.AccountC)}
[]sdk.Address{test.AccountB, test.AccountC}
stib, err := util.EncodeSignedTxn(makeBlockFunc().BlockHeader, stxnad.SignedTxn, stxnad.ApplyData)
require.NoError(t, err)

Expand All @@ -492,17 +492,40 @@ func TestWriterTxnParticipationTableNoPayout(t *testing.T) {
payset: []sdk.SignedTxnInBlock{stib},
expected: []txnParticipationRow{
{
addr: sdk.Address(test.AccountA),
addr: test.AccountA,
round: 2,
intra: 0,
},
{
addr: sdk.Address(test.AccountB),
addr: test.AccountB,
round: 2,
intra: 0,
},
{
addr: sdk.Address(test.AccountC),
addr: test.AccountC,
round: 2,
intra: 0,
},
},
}
tests = append(tests, testcase)
}
{
stxnad0 := test.MakeHeartbeatTxn(test.AccountA, test.AccountD)
stib0, err := util.EncodeSignedTxn(makeBlockFunc().BlockHeader, stxnad0.SignedTxn, stxnad0.ApplyData)
require.NoError(t, err)

testcase := testtype{
name: "heartbeat",
payset: []sdk.SignedTxnInBlock{stib0},
expected: []txnParticipationRow{
{
addr: test.AccountA,
round: 2,
intra: 0,
},
{
addr: test.AccountD,
round: 2,
intra: 0,
},
Expand Down Expand Up @@ -648,6 +671,40 @@ func TestWriterTxnParticipationTableWithPayout(t *testing.T) {
}
tests = append(tests, testcase)
}
{
stxnad0 := test.MakeHeartbeatTxn(test.AccountA, test.AccountD)
stib0, err := util.EncodeSignedTxn(makeBlockFunc().BlockHeader, stxnad0.SignedTxn, stxnad0.ApplyData)
require.NoError(t, err)

testcase := testtype{
name: "heartbeat",
payset: []sdk.SignedTxnInBlock{stib0},
expected: []txnParticipationRow{
{
addr: test.AccountA,
round: 2,
intra: 0,
},
{
addr: test.AccountD,
round: 2,
intra: 0,
},
// Payout involved accounts
{
addr: test.AccountE,
round: 2,
intra: 1,
},
{
addr: test.FeeAddr,
round: 2,
intra: 1,
},
},
}
tests = append(tests, testcase)
}

for _, testcase := range tests {
t.Run(testcase.name, func(t *testing.T) {
Expand Down
27 changes: 27 additions & 0 deletions util/test/account_testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"crypto/rand"
"crypto/sha512"
"fmt"
"os"

"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/util"

"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
Expand Down Expand Up @@ -352,6 +354,31 @@ func MakeAppCallWithInnerTxn(appSender, paymentSender, paymentReceiver, assetSen
return createApp
}

// MakeHeartbeatTxn creates a heartbeat transaction, overriding fields with the provided values.
func MakeHeartbeatTxn(sender, hbAddress sdk.Address) sdk.SignedTxnWithAD {
var hbTxn sdk.SignedTxn
_ = msgpack.Decode(loadResourceFileOrPanic("test_resources/heartbeat.txn"), &hbTxn)

hbTxn.Txn.Sender = sender
hbTxn.Txn.GenesisHash = GenesisHash
var fields = hbTxn.Txn.HeartbeatTxnFields
fields.HbAddress = hbAddress
return sdk.SignedTxnWithAD{
SignedTxn: hbTxn,
}
}

func loadResourceFileOrPanic(path string) []byte {
data, err := os.ReadFile(path)

if err != nil {
panic(fmt.Sprintf("Failed to load resource file: '%s'", path))
}
var ret idb.TxnRow
_ = msgpack.Decode(data, &ret)
return data
}

// MakeBlockForTxns takes some transactions and constructs a block compatible with the indexer import function.
func MakeBlockForTxns(prevHeader sdk.BlockHeader, inputs ...*sdk.SignedTxnWithAD) (sdk.Block, error) {
res := sdk.Block{BlockHeader: prevHeader}
Expand Down
Loading