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

algod: Migrate internal uses of v1 algod API to v2 #4684

Merged
merged 37 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
86fd07e
Delete kmd API affinity
algochoi Oct 12, 2022
c7f6cea
Delete affinity in algod
algochoi Oct 12, 2022
d3277ed
Migrate GetPendingTransactions
algochoi Oct 12, 2022
9dca911
Fix response field
algochoi Oct 13, 2022
5c846ba
Migrate Assets and Accounts to V2
algochoi Oct 18, 2022
ff0fb61
Fix linting and change pending transactions by addr
algochoi Oct 18, 2022
ad0606a
Change pending transaction and params/fee for v2 api
algochoi Oct 18, 2022
0e6c5ff
Change v1 block to v2/bookkeeping block response
algochoi Oct 20, 2022
60c2cba
Merge branch 'master' into v2-goal-migration
algochoi Oct 20, 2022
55f1662
Revise transaction parsing in tests
algochoi Oct 21, 2022
af4ae19
Fix asset call to include creatables
algochoi Oct 21, 2022
2ec5fc2
Fix asset field derefs
algochoi Oct 23, 2022
292b4f6
Try reverting goal waitfortxn
algochoi Oct 24, 2022
ca0eda3
Fix transaction encoding again
algochoi Oct 25, 2022
96bf392
Check for empty asset unit names to pass expect tests
algochoi Oct 25, 2022
08f14f1
Convert v1 endpoints to similar v2 endpoints and change tests
algochoi Oct 26, 2022
f69c7d3
Fix note test that was changed for debugging
algochoi Oct 26, 2022
5b0e7a7
Change pingpong tests to V2 api
algochoi Oct 27, 2022
1acdf98
Merge branch 'master' into v2-goal-migration
algochoi Oct 27, 2022
478dbec
Fix algoh mockClient tests
algochoi Oct 27, 2022
3125af5
Change send transaction API from v1 to v2
algochoi Oct 28, 2022
5c36058
Fix some tests regarding send transaction
algochoi Oct 28, 2022
8b212cb
Minor changes on comments and change expect test cases so error messa…
algochoi Oct 28, 2022
8c14f9c
Delete extraneous comments in client test
algochoi Nov 1, 2022
6e5f5bf
Rename PendingTransactionsStruct to PendingTransactions (#25)
michaeldiamant Nov 1, 2022
5ccca0d
use stateproof v2 api on tests
Nov 1, 2022
066d463
Delete extraneous function makeTestBlock inline
algochoi Nov 1, 2022
37a0812
Add blockstats test to check for event details (#26)
algochoi Nov 2, 2022
6af0e28
Merge branch 'v2-goal-migration' of https://github.com/algochoi/go-al…
algochoi Nov 2, 2022
99f2d2c
Change mockclient in algoh to make block with round number
algochoi Nov 2, 2022
bfe1a2f
Update cmd/algoh/blockstats.go
algochoi Nov 2, 2022
e1e2a4b
Add more error formatting for REST responses (#27)
jasonpaulos Nov 3, 2022
bb260ab
Change error messages on tests after client side parsing
algochoi Nov 3, 2022
bb5170f
Merge branch 'v2-goal-migration' of https://github.com/algochoi/go-al…
algochoi Nov 3, 2022
d21a9d6
Change http response message in SPFullPool test
algochoi Nov 3, 2022
5b680e3
Revise error message check
algochoi Nov 3, 2022
52f3b85
Delete old error message
algochoi Nov 3, 2022
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
15 changes: 12 additions & 3 deletions cmd/algoh/blockWatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import (
"sync"
"time"

"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/rpcs"
)

var log = logging.Base()

type blockListener interface {
init(uint64)
onBlock(v1.Block)
onBlock(rpcs.EncodedBlockCert)
}

type blockWatcher struct {
Expand Down Expand Up @@ -75,7 +76,8 @@ func (bw *blockWatcher) run(watchers []blockListener, stallDetect time.Duration,
for {
// Inner loop needed during catchup.
for {
block, err := bw.client.Block(curBlock)
// Get the raw block from the client, then parse the block so we can get the bookkeeping block and certificate for proposer address.
resp, err := bw.client.RawBlock(curBlock)

// Generally this error will be due to the new block not being ready. In the case of a stall we will
// return, causing the loop to restart and handle any possible stall/catchup.
Expand All @@ -89,6 +91,13 @@ func (bw *blockWatcher) run(watchers []blockListener, stallDetect time.Duration,
break
}

// Parse the raw block
michaeldiamant marked this conversation as resolved.
Show resolved Hide resolved
var block rpcs.EncodedBlockCert
err = protocol.DecodeReflect(resp, &block)
if err != nil {
return false
}

curBlock++
for _, watcher := range watchers {
watcher.onBlock(block)
Expand Down
4 changes: 2 additions & 2 deletions cmd/algoh/blockWatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"
"time"

"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
"github.com/algorand/go-algorand/rpcs"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func (l *testlistener) init(block uint64) {
atomic.AddUint32(&(l.initCount), 1)
}

func (l *testlistener) onBlock(block v1.Block) {
func (l *testlistener) onBlock(rpcs.EncodedBlockCert) {
atomic.AddUint32(&(l.blockCount), 1)
}

Expand Down
23 changes: 12 additions & 11 deletions cmd/algoh/blockstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package main
import (
"time"

"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
"github.com/algorand/go-algorand/logging/telemetryspec"
"github.com/algorand/go-algorand/rpcs"
)

const downtimeLimit time.Duration = 5 * time.Minute
Expand All @@ -34,20 +34,21 @@ type blockstats struct {
func (stats *blockstats) init(block uint64) {
}

func (stats *blockstats) onBlock(block v1.Block) {
func (stats *blockstats) onBlock(block rpcs.EncodedBlockCert) {
now := time.Now()
blockHeader := block.Block.BlockHeader

// Ensure we only create stats from consecutive blocks.
if stats.lastBlock+1 != block.Round {
stats.lastBlock = block.Round
if stats.lastBlock+1 != uint64(blockHeader.Round) {
stats.lastBlock = uint64(blockHeader.Round)
stats.lastBlockTime = now
return
}

// Grab unique users.
users := make(map[string]bool)
for _, tx := range block.Transactions.Transactions {
users[tx.From] = true
for _, tx := range block.Block.Payset {
users[tx.Txn.Sender.String()] = true
algochoi marked this conversation as resolved.
Show resolved Hide resolved
}

duration := now.Sub(stats.lastBlockTime)
Expand All @@ -57,15 +58,15 @@ func (stats *blockstats) onBlock(block v1.Block) {
}

stats.log.EventWithDetails(telemetryspec.Agreement, telemetryspec.BlockStatsEvent, telemetryspec.BlockStatsEventDetails{
Hash: block.Hash,
OriginalProposer: block.Proposer,
Round: block.Round,
Transactions: uint64(len(block.Transactions.Transactions)),
Hash: block.Block.Hash().String(),
OriginalProposer: block.Certificate.Proposal.OriginalProposer.String(), // v2 API no longer returns the Block Proposer; we need to decode a raw block and retrieve proposer from block certificate.
algochoi marked this conversation as resolved.
Show resolved Hide resolved
Round: uint64(blockHeader.Round),
Transactions: uint64(len(block.Block.Payset)),
ActiveUsers: uint64(len(users)),
AgreementDurationMs: uint64(duration.Nanoseconds() / 1000 / 1000),
NetworkDowntimeMs: uint64(downtime.Nanoseconds() / 1000 / 1000),
})

stats.lastBlock = block.Round
stats.lastBlock = uint64(blockHeader.Round)
stats.lastBlockTime = now
}
25 changes: 18 additions & 7 deletions cmd/algoh/blockstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"testing"
"time"

"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/logging/telemetryspec"
"github.com/algorand/go-algorand/rpcs"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
)
Expand All @@ -42,18 +44,27 @@ func (mes *MockEventSender) EventWithDetails(category telemetryspec.Category, id
mes.events = append(mes.events, event{category: category, identifier: identifier, details: details})
}

// Helper method to create an EncodedBlockCert for the block handler.
func makeTestBlock(round uint64) rpcs.EncodedBlockCert {
return rpcs.EncodedBlockCert{Block: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: basics.Round(round)}}}
}

func TestConsecutiveBlocks(t *testing.T) {
partitiontest.PartitionTest(t)
sender := MockEventSender{}
bs := blockstats{log: &sender}

bs.onBlock(v1.Block{Round: 300})
makeTestBlock := func(round uint64) rpcs.EncodedBlockCert {
return rpcs.EncodedBlockCert{Block: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: basics.Round(round)}}}
}

bs.onBlock(makeTestBlock(300))
// first consecutive block
bs.onBlock(v1.Block{Round: 301})
bs.onBlock(makeTestBlock(301))
// reset
bs.onBlock(v1.Block{Round: 303})
bs.onBlock(makeTestBlock(303))
// second consecutive block
bs.onBlock(v1.Block{Round: 304})
bs.onBlock(makeTestBlock(304))

require.Equal(t, 2, len(sender.events))
}
Expand All @@ -70,9 +81,9 @@ func TestAgreementTime(t *testing.T) {
bs := blockstats{log: &sender}

start := time.Now()
bs.onBlock(v1.Block{Round: 300})
bs.onBlock(makeTestBlock(300))
time.Sleep(sleepTime)
bs.onBlock(v1.Block{Round: 301})
bs.onBlock(makeTestBlock(301))
end := time.Now()

require.Equal(t, 1, len(sender.events))
Expand Down
3 changes: 1 addition & 2 deletions cmd/algoh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (
"context"

generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
)

// Client is a minimal interface for the RestClient
type Client interface {
Status() (generatedV2.NodeStatusResponse, error)
Block(round uint64) (v1.Block, error)
RawBlock(round uint64) ([]byte, error)
GetGoRoutines(ctx context.Context) (string, error)
HealthCheck() error
}
6 changes: 3 additions & 3 deletions cmd/algoh/deadman.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"time"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
"github.com/algorand/go-algorand/logging/telemetryspec"
"github.com/algorand/go-algorand/rpcs"
)

type deadManWatcher struct {
Expand Down Expand Up @@ -88,8 +88,8 @@ func (w deadManWatcher) run(initBlock uint64) {
}
}

func (w deadManWatcher) onBlock(block v1.Block) {
w.newBlockChan <- block.Round
func (w deadManWatcher) onBlock(block rpcs.EncodedBlockCert) {
w.newBlockChan <- uint64(block.Block.BlockHeader.Round)
}

func (w deadManWatcher) reportDeadManTimeout(curBlock uint64) (err error) {
Expand Down
20 changes: 12 additions & 8 deletions cmd/algoh/mockClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"fmt"

generatedV2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
"github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/rpcs"
)

//////////////////////////////////////
Expand All @@ -36,10 +39,10 @@ func makeNodeStatuses(blocks ...uint64) (ret []generatedV2.NodeStatusResponse) {
return ret
}

func makeBlocks(blocks ...uint64) (ret map[uint64]v1.Block) {
ret = map[uint64]v1.Block{}
func makeBlocks(blocks ...uint64) (ret map[uint64]rpcs.EncodedBlockCert) {
ret = map[uint64]rpcs.EncodedBlockCert{}
for _, block := range blocks {
ret[block] = v1.Block{Round: block}
ret[block] = rpcs.EncodedBlockCert{Block: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: basics.Round(300)}}}
}
return ret
}
Expand All @@ -54,10 +57,10 @@ type mockClient struct {
error []error
status []generatedV2.NodeStatusResponse
routine []string
block map[uint64]v1.Block
block map[uint64]rpcs.EncodedBlockCert
}

func makeMockClient(error []error, status []generatedV2.NodeStatusResponse, block map[uint64]v1.Block, routine []string) mockClient {
func makeMockClient(error []error, status []generatedV2.NodeStatusResponse, block map[uint64]rpcs.EncodedBlockCert, routine []string) mockClient {
return mockClient{
BlockCalls: make(map[uint64]int),
error: error,
Expand Down Expand Up @@ -90,15 +93,16 @@ func (c *mockClient) Status() (s generatedV2.NodeStatusResponse, e error) {
return
}

func (c *mockClient) Block(block uint64) (b v1.Block, e error) {
func (c *mockClient) RawBlock(block uint64) (b []byte, e error) {
c.BlockCalls[block]++
e = c.nextError()
b, ok := c.block[block]
bl, ok := c.block[block]
if !ok {
if e == nil {
e = fmt.Errorf("test is missing block %d", block)
}
}
b = protocol.EncodeReflect(bl)
return
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func printAccountInfo(client libgoal.Client, address string, onlyShowAssetIds bo
_, units = unicodePrintable(*createdAsset.Params.UnitName)
}

total := assetDecimalsFmt(createdAsset.Params.Total, uint32(createdAsset.Params.Decimals))
total := assetDecimalsFmt(createdAsset.Params.Total, createdAsset.Params.Decimals)

url := ""
if createdAsset.Params.Url != nil {
Expand All @@ -618,7 +618,7 @@ func printAccountInfo(client libgoal.Client, address string, onlyShowAssetIds bo
fmt.Fprintf(report, "\tID %d, error\n", assetHolding.AssetId)
}

amount := assetDecimalsFmt(assetHolding.Amount, uint32(assetParams.Params.Decimals))
amount := assetDecimalsFmt(assetHolding.Amount, assetParams.Params.Decimals)

assetName := "<unnamed>"
if assetParams.Params.Name != nil {
Expand Down Expand Up @@ -1137,15 +1137,15 @@ var listParticipationKeysCmd = &cobra.Command{
fmt.Printf(rowFormat, "Registered", "Account", "ParticipationID", "Last Used", "First round", "Last round")
for _, part := range parts {
onlineInfoStr := "unknown"
onlineAccountInfo, err := client.AccountInformation(part.Address)
onlineAccountInfo, err := client.AccountInformationV2(part.Address, false)
if err == nil {
votingBytes := part.Key.VoteParticipationKey
vrfBytes := part.Key.SelectionParticipationKey
if onlineAccountInfo.Participation != nil &&
(string(onlineAccountInfo.Participation.ParticipationPK) == string(votingBytes[:])) &&
(string(onlineAccountInfo.Participation.VRFPK) == string(vrfBytes[:])) &&
(onlineAccountInfo.Participation.VoteFirst == part.Key.VoteFirstValid) &&
(onlineAccountInfo.Participation.VoteLast == part.Key.VoteLastValid) &&
(string(onlineAccountInfo.Participation.VoteParticipationKey) == string(votingBytes[:])) &&
(string(onlineAccountInfo.Participation.SelectionParticipationKey) == string(vrfBytes[:])) &&
(onlineAccountInfo.Participation.VoteFirstValid == part.Key.VoteFirstValid) &&
(onlineAccountInfo.Participation.VoteLastValid == part.Key.VoteLastValid) &&
(onlineAccountInfo.Participation.VoteKeyDilution == part.Key.VoteKeyDilution) {
onlineInfoStr = "yes"
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ var createAppCmd = &cobra.Command{
if err != nil {
reportErrorf(err.Error())
}
if txn.TransactionResults != nil && txn.TransactionResults.CreatedAppIndex != 0 {
reportInfof("Created app with app index %d", txn.TransactionResults.CreatedAppIndex)
if txn.ApplicationIndex != nil && *txn.ApplicationIndex != 0 {
reportInfof("Created app with app index %d", *txn.ApplicationIndex)
}
}
} else {
Expand Down
Loading