Skip to content
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
12 changes: 10 additions & 2 deletions data/bookkeeping/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,11 @@ func (bh BlockHeader) DecodeSignedTxn(stb transactions.SignedTxnInBlock) (transa
st := stb.SignedTxn
ad := stb.ApplyData

proto := config.Consensus[bh.CurrentProtocol]
proto, ok := config.Consensus[bh.CurrentProtocol]
if !ok {
return transactions.SignedTxn{}, transactions.ApplyData{},
fmt.Errorf("consensus protocol %s not found", bh.CurrentProtocol)
}
if !proto.SupportSignedTxnInBlock {
return st, transactions.ApplyData{}, nil
}
Expand Down Expand Up @@ -708,7 +712,11 @@ func (bh BlockHeader) DecodeSignedTxn(stb transactions.SignedTxnInBlock) (transa
func (bh BlockHeader) EncodeSignedTxn(st transactions.SignedTxn, ad transactions.ApplyData) (transactions.SignedTxnInBlock, error) {
var stb transactions.SignedTxnInBlock

proto := config.Consensus[bh.CurrentProtocol]
proto, ok := config.Consensus[bh.CurrentProtocol]
if !ok {
return transactions.SignedTxnInBlock{},
fmt.Errorf("consensus protocol %s not found", bh.CurrentProtocol)
}
if !proto.SupportSignedTxnInBlock {
stb.SignedTxn = st
return stb, nil
Expand Down
1 change: 1 addition & 0 deletions data/bookkeeping/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func TestEncodeDecodeSignedTxn(t *testing.T) {
var b Block
b.BlockHeader.GenesisID = "foo"
crypto.RandBytes(b.BlockHeader.GenesisHash[:])
b.CurrentProtocol = protocol.ConsensusFuture

var tx transactions.SignedTxn
tx.Txn.GenesisID = b.BlockHeader.GenesisID
Expand Down
24 changes: 17 additions & 7 deletions node/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import (
"github.com/algorand/go-algorand/test/partitiontest"
)

const testGenesisID string = "foo"

var genesisHash = crypto.Digest{0x1, 0x2, 0x3}

type IndexSuite struct {
suite.Suite
idx *Indexer
Expand Down Expand Up @@ -62,14 +66,18 @@ func (s *IndexSuite) SetupSuite() {
var txnEnc []transactions.SignedTxnInBlock
b := bookkeeping.Block{
BlockHeader: bookkeeping.BlockHeader{
Round: basics.Round(uint64(i + 2)),
TimeStamp: time.Now().Unix(),
Round: basics.Round(uint64(i + 2)),
TimeStamp: time.Now().Unix(),
GenesisID: testGenesisID,
GenesisHash: genesisHash,
UpgradeState: bookkeeping.UpgradeState{
CurrentProtocol: protocol.ConsensusFuture,
},
},
}

chunkSize := numOfTransactions / numOfBlocks
for t := i * chunkSize; t < (i+1)*chunkSize; t++ {

txid, err := b.EncodeSignedTxn(s.txns[t], transactions.ApplyData{})
require.NoError(s.T(), err)
txnEnc = append(txnEnc, txid)
Expand Down Expand Up @@ -230,10 +238,12 @@ func generateTestObjects(numTxs, numAccs int) ([]transactions.Transaction, []tra

txs[i] = transactions.Transaction{
Header: transactions.Header{
Sender: addresses[s],
Fee: basics.MicroAlgos{Raw: f},
FirstValid: basics.Round(iss),
LastValid: basics.Round(exp),
Sender: addresses[s],
Fee: basics.MicroAlgos{Raw: f},
FirstValid: basics.Round(iss),
LastValid: basics.Round(exp),
GenesisID: testGenesisID,
GenesisHash: genesisHash,
},
}

Expand Down
8 changes: 7 additions & 1 deletion node/topAccountListener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"testing"

"github.com/algorand/go-algorand/crypto"
"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 @@ -284,14 +285,19 @@ func TestInit(t *testing.T) {

func makeBlockWithTxnFor(senders []byte, receivers []byte) bookkeeping.Block {
var blk bookkeeping.Block
blk.BlockHeader.GenesisID = "foo"
crypto.RandBytes(blk.BlockHeader.GenesisHash[:])
blk.CurrentProtocol = protocol.ConsensusFuture

paysets := make([]transactions.SignedTxnInBlock, 0, len(receivers))
for i, b := range receivers {
txib, err := blk.EncodeSignedTxn(transactions.SignedTxn{
Txn: transactions.Transaction{
Type: protocol.PaymentTx,
Header: transactions.Header{
Sender: basics.Address{senders[i]},
Sender: basics.Address{senders[i]},
GenesisID: blk.BlockHeader.GenesisID,
GenesisHash: blk.BlockHeader.GenesisHash,
},
PaymentTxnFields: transactions.PaymentTxnFields{
Receiver: basics.Address{b},
Expand Down