Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix-go-mod-secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Sep 14, 2021
2 parents 852b0fc + 08d31fa commit aab9db1
Show file tree
Hide file tree
Showing 42 changed files with 3,613 additions and 96,466 deletions.
41 changes: 26 additions & 15 deletions cmd/netgoal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func generateNetworkGoalTemplate(templateFilename string, wallets, relays, nodes
}

if npnHosts > 0 {
for walletIndex < wallets {
for walletIndex < npnHosts {
for nodei, node := range template.Nodes {
if node.Name[0:4] != "nonP" {
continue
Expand All @@ -296,11 +296,11 @@ func generateNetworkGoalTemplate(templateFilename string, wallets, relays, nodes
}
template.Nodes[nodei].Wallets = append(template.Nodes[nodei].Wallets, wallet)
walletIndex++
if walletIndex >= wallets {
if walletIndex >= npnHosts {
break
}
}
if walletIndex >= wallets {
if walletIndex >= npnHosts {
break
}
}
Expand Down Expand Up @@ -399,9 +399,10 @@ func generateNetworkTemplate(templateFilename string, wallets, relays, nodeHosts
}
}

// one wallet per NPN host to concentrate stake
if npnHosts > 0 {
walletIndex := 0
for walletIndex < wallets {
for walletIndex < npnHosts {
for hosti := range network.Hosts {
for nodei, node := range network.Hosts[hosti].Nodes {
if node.Name[0:4] != "nonP" {
Expand All @@ -413,11 +414,11 @@ func generateNetworkTemplate(templateFilename string, wallets, relays, nodeHosts
}
network.Hosts[hosti].Nodes[nodei].Wallets = append(network.Hosts[hosti].Nodes[nodei].Wallets, wallet)
walletIndex++
if walletIndex >= wallets {
if walletIndex >= npnHosts {
break
}
}
if walletIndex >= wallets {
if walletIndex >= npnHosts {
break
}
}
Expand Down Expand Up @@ -465,19 +466,29 @@ func saveGoalTemplateToDisk(template netdeploy.NetworkTemplate, filename string)
}

func generateWalletGenesisData(wallets, npnHosts int) gen.GenesisData {
ratZero := big.NewRat(int64(0), int64(1))
ratHundred := big.NewRat(int64(100), int64(1))
data := gen.DefaultGenesis
totalWallets := wallets + npnHosts
data.Wallets = make([]gen.WalletData, totalWallets)
participatingNodeStake := big.NewRat(int64(100), int64(wallets))
nonParticipatingNodeStake := ratZero
if npnHosts > 0 {
wallets = 2 * wallets
// split participating an non participating stake evenly
participatingNodeStake = big.NewRat(int64(50), int64(wallets))
nonParticipatingNodeStake = big.NewRat(int64(50), int64(npnHosts))
}
data.Wallets = make([]gen.WalletData, wallets)
stake := big.NewRat(int64(100), int64(wallets))

ratZero := big.NewRat(int64(0), int64(1))
ratHundred := big.NewRat(int64(100), int64(1))

stake := ratZero
stakeSum := new(big.Rat).Set(ratZero)
for i := 0; i < wallets; i++ {
if i == (wallets - 1) {
for i := 0; i < totalWallets; i++ {

if i < wallets {
stake = participatingNodeStake
} else {
stake = nonParticipatingNodeStake
}
if i == (totalWallets - 1) {
// use the last wallet to workaround roundoff and get back to 1.0
stake = stake.Sub(new(big.Rat).Set(ratHundred), stakeSum)
}
Expand All @@ -486,7 +497,7 @@ func generateWalletGenesisData(wallets, npnHosts int) gen.GenesisData {
Name: "Wallet" + strconv.Itoa(i+1), // Wallet names are 1-based for this template
Stake: floatStake,
}
if (i < (wallets / 2)) || (npnHosts == 0) {
if i < wallets {
w.Online = true
}
stakeSum = stakeSum.Add(stakeSum, stake)
Expand Down
8 changes: 4 additions & 4 deletions cmd/opdoc/opdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func assetHoldingFieldsMarkdown(out io.Writer) {

func assetParamsFieldsMarkdown(out io.Writer) {
fmt.Fprintf(out, "\n`asset_params_get` Fields:\n\n")
fieldTableMarkdown(out, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs)
fieldTableMarkdown(out, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs())
}

func appParamsFieldsMarkdown(out io.Writer) {
fmt.Fprintf(out, "\n`app_params_get` Fields:\n\n")
fieldTableMarkdown(out, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs)
fieldTableMarkdown(out, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs())
}

func ecDsaCurvesMarkdown(out io.Writer) {
Expand Down Expand Up @@ -373,11 +373,11 @@ func main() {
assetholding.Close()

assetparams, _ := os.Create("asset_params_fields.md")
fieldTableMarkdown(assetparams, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs)
fieldTableMarkdown(assetparams, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs())
assetparams.Close()

appparams, _ := os.Create("app_params_fields.md")
fieldTableMarkdown(appparams, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs)
fieldTableMarkdown(appparams, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs())
appparams.Close()

langspecjs, _ := os.Create("langspec.json")
Expand Down
5 changes: 5 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,11 @@ func initConsensusProtocols() {

// Enable App calls to pool budget in grouped transactions
vFuture.EnableAppCostPooling = true

// Enable Inner Transactions, and set maximum number. 0 value is
// disabled. Value > 0 also activates storage of creatable IDs in
// ApplyData, as that is required to support REST API when inner
// transactions are activated.
vFuture.MaxInnerTransactions = 16

// Allow 50 app opt ins
Expand Down
22 changes: 20 additions & 2 deletions daemon/algod/api/server/v1/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func computeCreatableIndexInPayset(tx node.TxnWithStatus, txnCounter uint64, pay
// computeAssetIndexFromTxn returns the created asset index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint64) {
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) uint64 {
// Must have ledger
if l == nil {
return 0
Expand All @@ -413,6 +413,15 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint6
return 0
}

aidx := uint64(tx.ApplyData.ConfigAsset)
if aidx > 0 {
return aidx
}
// If there is no ConfigAsset in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aid. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand All @@ -430,7 +439,7 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint6
// computeAppIndexFromTxn returns the created app index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint64) {
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) uint64 {
// Must have ledger
if l == nil {
return 0
Expand All @@ -448,6 +457,15 @@ func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint64)
return 0
}

aidx := uint64(tx.ApplyData.ApplicationID)
if aidx > 0 {
return aidx
}
// If there is no ApplicationID in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aidx. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand Down
33 changes: 26 additions & 7 deletions daemon/algod/api/server/v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func computeCreatableIndexInPayset(tx node.TxnWithStatus, txnCounter uint64, pay
// computeAssetIndexFromTxn returns the created asset index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint64) {
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) *uint64 {
// Must have ledger
if l == nil {
return nil
Expand All @@ -128,6 +128,15 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint
return nil
}

aid := uint64(tx.ApplyData.ConfigAsset)
if aid > 0 {
return &aid
}
// If there is no ConfigAsset in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aid. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand All @@ -145,7 +154,7 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint
// computeAppIndexFromTxn returns the created app index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint64) {
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) *uint64 {
// Must have ledger
if l == nil {
return nil
Expand All @@ -163,6 +172,15 @@ func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint64
return nil
}

aid := uint64(tx.ApplyData.ApplicationID)
if aid > 0 {
return &aid
}
// If there is no ApplicationID in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aid. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand Down Expand Up @@ -283,12 +301,12 @@ func convertLogs(txn node.TxnWithStatus) *[][]byte {
func convertInners(txn *node.TxnWithStatus) *[]preEncodedTxInfo {
inner := make([]preEncodedTxInfo, len(txn.ApplyData.EvalDelta.InnerTxns))
for i, itxn := range txn.ApplyData.EvalDelta.InnerTxns {
inner[i] = convertTxn(&itxn)
inner[i] = convertInnerTxn(&itxn)
}
return &inner
}

func convertTxn(txn *transactions.SignedTxnWithAD) preEncodedTxInfo {
func convertInnerTxn(txn *transactions.SignedTxnWithAD) preEncodedTxInfo {
// This copies from handlers.PendingTransactionInformation, with
// simplifications because we have a SignedTxnWithAD rather than
// TxnWithStatus, and we know this txn has committed.
Expand All @@ -301,9 +319,10 @@ func convertTxn(txn *transactions.SignedTxnWithAD) preEncodedTxInfo {
response.ReceiverRewards = &txn.ApplyData.ReceiverRewards.Raw
response.CloseRewards = &txn.ApplyData.CloseRewards.Raw

// Indexes can't be set until we allow acfg or appl
// response.AssetIndex = computeAssetIndexFromTxn(txn, v2.Node.Ledger())
// response.ApplicationIndex = computeAppIndexFromTxn(txn, v2.Node.Ledger())
// Since this is an inner txn, we know these indexes will be populated. No
// need to search payset for IDs
response.AssetIndex = numOrNil(uint64(txn.ApplyData.ConfigAsset))
response.ApplicationIndex = numOrNil(uint64(txn.ApplyData.ApplicationID))

// Deltas, Logs, and Inners can not be set until we allow appl
// response.LocalStateDelta, response.GlobalStateDelta = convertToDeltas(txn)
Expand Down
1 change: 1 addition & 0 deletions data/basics/msgp_gen_test.go

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

2 changes: 1 addition & 1 deletion data/pools/transactionPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func (pool *TransactionPool) isAssemblyTimedOut() bool {
// we have no deadline, so no reason to timeout.
return false
}
generateBlockDuration := generateBlockBaseDuration + time.Duration(pool.pendingBlockEvaluator.TxnCounter())*generateBlockTransactionDuration
generateBlockDuration := generateBlockBaseDuration + time.Duration(pool.pendingBlockEvaluator.PaySetSize())*generateBlockTransactionDuration
return time.Now().After(pool.assemblyDeadline.Add(-generateBlockDuration))
}

Expand Down
Loading

0 comments on commit aab9db1

Please sign in to comment.