Skip to content
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
Prev Previous commit
Next Next commit
Merge branch 'develop' of https://github.com/algorand/indexer into sh…
…iqi/perf
  • Loading branch information
shiqizng committed Feb 14, 2022
commit 674f043a5551182a1816e621b14d816ffb953341
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ commands:
- run: make test
- run: make test-generate
- run: make fakepackage
- run: make e2e
# - run: make e2e

run_tests_nightly:
steps:
Expand All @@ -118,7 +118,7 @@ commands:
- run: make test
- run: make test-generate
- run: make fakepackage
- run: make e2e
# - run: make e2e
- run: make indexer-v-algod

upload_coverage:
Expand Down
1 change: 1 addition & 0 deletions api/converter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD
VoteLastValid: uint64Ptr(uint64(stxn.Txn.VoteLast)),
VoteKeyDilution: uint64Ptr(stxn.Txn.VoteKeyDilution),
VoteParticipationKey: byteSliceOmitZeroPtr(stxn.Txn.VotePK[:]),
StateProofKey: byteSliceOmitZeroPtr(stxn.Txn.StateProofPK[:]),
}
keyreg = &k
case protocol.AssetConfigTx:
Expand Down
295 changes: 148 additions & 147 deletions api/generated/common/routes.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions api/generated/common/types.go

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

259 changes: 130 additions & 129 deletions api/generated/v2/routes.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions api/generated/v2/types.go

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

95 changes: 94 additions & 1 deletion api/handlers_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"testing"
"time"

"github.com/algorand/go-algorand/crypto"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/require"

"github.com/algorand/go-algorand-sdk/encoding/json"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
Expand Down Expand Up @@ -44,7 +46,7 @@ func setupIdb(t *testing.T, genesis bookkeeping.Genesis, genesisBlock bookkeepin
return db, newShutdownFunc
}

func TestApplicationHander(t *testing.T) {
func TestApplicationHandler(t *testing.T) {
db, shutdownFunc := setupIdb(t, test.MakeGenesis(), test.MakeGenesisBlock())
defer shutdownFunc()

Expand Down Expand Up @@ -343,6 +345,97 @@ func TestPagingRootTxnDeduplication(t *testing.T) {
})
}

func TestKeyregTransactionWithStateProofKeys(t *testing.T) {
db, shutdownFunc := setupIdb(t, test.MakeGenesis(), test.MakeGenesisBlock())
defer shutdownFunc()

///////////
// Given // A block containing a key reg txn with state proof key
///////////
var votePK crypto.OneTimeSignatureVerifier
votePK[0] = 1

var selectionPK crypto.VRFVerifier
selectionPK[0] = 1

var stateProofPK merklesignature.Verifier
stateProofPK[0] = 1

txn := transactions.SignedTxnWithAD{
SignedTxn: transactions.SignedTxn{
Txn: transactions.Transaction{
Type: "keyreg",
Header: transactions.Header{
Sender: test.AccountA,
GenesisHash: test.GenesisHash,
},
KeyregTxnFields: transactions.KeyregTxnFields{
VotePK: votePK,
SelectionPK: selectionPK,
StateProofPK: stateProofPK,
VoteFirst: basics.Round(0),
VoteLast: basics.Round(100),
VoteKeyDilution: 1000,
Nonparticipation: false,
},
},
Sig: test.Signature,
},
}

block, err := test.MakeBlockForTxns(test.MakeGenesisBlock().BlockHeader, &txn)
require.NoError(t, err)

err = db.AddBlock(&block)
require.NoError(t, err, "failed to commit")

e := echo.New()
{
//////////
// When // We query the txn
//////////
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/v2/transactions/:txid")
api := &ServerImplementation{db: db}
err = api.LookupTransaction(c, txn.Txn.ID().String())
require.NoError(t, err)
require.Equal(t, http.StatusOK, rec.Code)
//////////
// Then // The key reg txn response has state proof key
//////////
var response generated.TransactionResponse
data := rec.Body.Bytes()
err = json.Decode(data, &response)
require.NoError(t, err)
require.NotNil(t, response.Transaction.KeyregTransaction.StateProofKey)
require.Equal(t, stateProofPK[:], *response.Transaction.KeyregTransaction.StateProofKey)
}
{
//////////
// And // Account is online with state proof key
//////////
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/v2/accounts/:account-id")
api := &ServerImplementation{db: db}
params := generated.LookupAccountByIDParams{}
err = api.LookupAccountByID(c, test.AccountA.String(), params)
require.NoError(t, err)
require.Equal(t, http.StatusOK, rec.Code)

var acctResp generated.AccountResponse
data := rec.Body.Bytes()
err = json.Decode(data, &acctResp)
require.NoError(t, err)
require.NotNil(t, acctResp.Account)
require.NotNil(t, acctResp.Account.Participation.StateProofKey)
require.Equal(t, stateProofPK[:], *acctResp.Account.Participation.StateProofKey)
}
}

func TestVersion(t *testing.T) {
///////////
// Given // An API and context
Expand Down
65 changes: 32 additions & 33 deletions api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/stretchr/testify/require"

"github.com/algorand/go-algorand-sdk/encoding/msgpack"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
Expand Down Expand Up @@ -332,6 +334,15 @@ func TestFetchTransactions(t *testing.T) {
loadTransactionFromFile("test_resources/keyreg.response"),
},
},
{
name: "Key Registration with state proof key",
txnBytes: [][]byte{
loadResourceFileOrPanic("test_resources/keyregwithsprfkey.txn"),
},
response: []generated.Transaction{
loadTransactionFromFile("test_resources/keyregwithsprfkey.response"),
},
},
{
name: "Asset Configuration",
txnBytes: [][]byte{
Expand Down Expand Up @@ -519,8 +530,8 @@ func TestFetchTransactions(t *testing.T) {
response []generated.Transaction
created uint64
}{
name: "Application inner asset create",
txnBytes: [][]byte{createTxn(t, "test_resources/app_call_inner_acfg.txn")},
name: "Key Registration with state proof key",
txnBytes: [][]byte{createTxn(t, "test_resources/keyregwithsprfkey.txn")},
})
}

Expand Down Expand Up @@ -628,49 +639,37 @@ func TestFetchAccountsRewindRoundTooLarge(t *testing.T) {

// createTxn allows saving msgp-encoded canonical object to a file in order to add more test data
func createTxn(t *testing.T, target string) []byte {
defer assert.Fail(t, "this method should only be used for generating test inputs.")
addr1, err := basics.UnmarshalChecksumAddress("PT4K5LK4KYIQYYRAYPAZIEF47NVEQRDX3CPYWJVH25LKO2METIRBKRHRAE")
assert.Error(t, err)
addr2, err := basics.UnmarshalChecksumAddress("PIJRXIH5EJF7HT43AZQOQBPEZUTTCJCZ3E5U3QHLE33YP2ZHGXP7O7WN3U")
assert.Error(t, err)
var votePK crypto.OneTimeSignatureVerifier
votePK[0] = 1

var selectionPK crypto.VRFVerifier
selectionPK[0] = 1

var sprfkey merklesignature.Verifier
sprfkey[0] = 1

stxnad := transactions.SignedTxnWithAD{
SignedTxn: transactions.SignedTxn{
Txn: transactions.Transaction{
Type: protocol.ApplicationCallTx,
Type: protocol.KeyRegistrationTx,
Header: transactions.Header{
Sender: addr1,
},
ApplicationCallTxnFields: transactions.ApplicationCallTxnFields{
ApplicationID: 444,
},
},
},
ApplyData: transactions.ApplyData{
EvalDelta: transactions.EvalDelta{
InnerTxns: []transactions.SignedTxnWithAD{
{
SignedTxn: transactions.SignedTxn{
Txn: transactions.Transaction{
Type: protocol.AssetConfigTx,
Header: transactions.Header{
Sender: addr2,
Fee: basics.MicroAlgos{Raw: 654},
FirstValid: 3,
},
AssetConfigTxnFields: transactions.AssetConfigTxnFields{
AssetParams: basics.AssetParams{
URL: "http://example.com",
},
},
},
},
ApplyData: transactions.ApplyData{
ConfigAsset: 555,
},
},
KeyregTxnFields: transactions.KeyregTxnFields{
VotePK: votePK,
SelectionPK: selectionPK,
StateProofPK: sprfkey,
VoteFirst: basics.Round(0),
VoteLast: basics.Round(100),
VoteKeyDilution: 1000,
Nonparticipation: false,
},
},
},
ApplyData: transactions.ApplyData{},
}

data := msgpack.Encode(stxnad)
Expand Down
10 changes: 10 additions & 0 deletions api/indexer.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,11 @@
"description": "\\[vote\\] root participation public key (if any) currently registered for this round.",
"type": "string",
"format": "byte"
},
"state-proof-key": {
"description": "\\[stprf\\] Root of the state proof key (if any)",
"type": "string",
"format": "byte"
}
}
},
Expand Down Expand Up @@ -1886,6 +1891,11 @@
"description": "\\[votekey\\] Participation public key used in key registration transactions.",
"type": "string",
"format": "byte"
},
"state-proof-key": {
"description": "\\[sprfkey\\] State proof key used in key registration transactions.",
"type": "string",
"format": "byte"
}
}
},
Expand Down
12 changes: 12 additions & 0 deletions api/indexer.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@
"pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
"type": "string"
},
"state-proof-key": {
"description": "\\[stprf\\] Root of the state proof key (if any)",
"format": "byte",
"pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
"type": "string"
},
"vote-first-valid": {
"description": "\\[voteFst\\] First round for which this participation is valid.",
"type": "integer"
Expand Down Expand Up @@ -1694,6 +1700,12 @@
"pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
"type": "string"
},
"state-proof-key": {
"description": "\\[sprfkey\\] State proof key used in key registration transactions.",
"format": "byte",
"pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
"type": "string"
},
"vote-first-valid": {
"description": "\\[votefst\\] First round this participation key is valid.",
"type": "integer"
Expand Down
1 change: 1 addition & 0 deletions api/test_resources/keyregwithsprfkey.response
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"close-rewards":0,"closing-amount":0,"confirmed-round":1,"fee":0,"first-valid":0,"id":"U3M6XPKUOSOWFIINOIU7HVPAZTITVGWULMFQ2SKJFC3EQORIPRNQ","intra-round-offset":2,"keyreg-transaction":{"non-participation":false,"selection-participation-key":"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","state-proof-key":"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","vote-first-valid":0,"vote-key-dilution":1000,"vote-last-valid":100,"vote-participation-key":"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="},"last-valid":0,"receiver-rewards":0,"round-time":1636127799,"sender":"PT4K5LK4KYIQYYRAYPAZIEF47NVEQRDX3CPYWJVH25LKO2METIRBKRHRAE","sender-rewards":0,"signature":{},"tx-type":"keyreg"}
Binary file added api/test_resources/keyregwithsprfkey.txn
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/algorand-indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func configureLogger() error {
if logFile == "-" {
logger.SetOutput(os.Stdout)
} else if logFile != "" {
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
replace github.com/algorand/go-algorand => ./third_party/go-algorand

require (
github.com/algorand/go-algorand v0.0.0-20210803210013-358a2e1609c9
github.com/algorand/go-algorand v0.0.0-20220211161928-53b157beb10f
github.com/algorand/go-algorand-sdk v1.9.1
github.com/algorand/go-codec/codec v1.1.7
github.com/algorand/oapi-codegen v1.3.5-algorand5
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.