Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit df4e244

Browse files
authored
Merge pull request #719 from iotaledger/feat/benchmark-workscore
New WorkScoreParameters
2 parents 3f5b497 + bc3d61c commit df4e244

File tree

7 files changed

+956
-42
lines changed

7 files changed

+956
-42
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/multiformats/go-varint v0.0.7
3737
github.com/otiai10/copy v1.14.0
3838
github.com/prometheus/client_golang v1.18.0
39+
github.com/sajari/regression v1.0.1
3940
github.com/spf13/pflag v1.0.5
4041
github.com/stretchr/testify v1.8.4
4142
github.com/zyedidia/generic v1.2.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
580580
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
581581
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
582582
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
583+
github.com/sajari/regression v1.0.1 h1:iTVc6ZACGCkoXC+8NdqH5tIreslDTT/bXxT6OmHR5PE=
584+
github.com/sajari/regression v1.0.1/go.mod h1:NeG/XTW1lYfGY7YV/Z0nYDV/RGh3wxwd1yW46835flM=
583585
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
584586
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
585587
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=

pkg/tests/accounts_test.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Test_TransitionAndDestroyAccount(t *testing.T) {
3636
// Nil address will be replaced with the address generated from genesis seed.
3737
Address: nil,
3838
// Set an amount enough to cover storage deposit and more issuer keys.
39-
Amount: mock.MinIssuerAccountAmount(ts.API.ProtocolParameters()) * 10,
39+
Amount: mock.MinIssuerAccountAmount(ts.API.ProtocolParameters()) * 2,
4040
Mana: 0,
4141
// AccountID is derived from this field, so this must be set uniquely for each account.
4242
IssuerKey: oldGenesisOutputKey,
@@ -472,7 +472,13 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
472472
node1 := ts.AddValidatorNode("node1")
473473
node2 := ts.AddNode("node2")
474474

475-
wallet1BIC := iotago.BlockIssuanceCredits(100_000_000)
475+
testPayload := &iotago.TaggedData{}
476+
testPayloadWorkScore := lo.PanicOnErr(testPayload.WorkScore(ts.API.ProtocolParameters().WorkScoreParameters()))
477+
minRMC := ts.API.ProtocolParameters().CongestionControlParameters().MinReferenceManaCost
478+
testPayloadCost := iotago.BlockIssuanceCredits(testPayloadWorkScore) * iotago.BlockIssuanceCredits(minRMC)
479+
480+
// wallet 1 starts with enough BIC to issue two test payloads
481+
wallet1BIC := 2 * testPayloadCost
476482
wallet2BIC := iotago.BlockIssuanceCredits(0)
477483

478484
wallet1 := ts.AddGenesisWallet("wallet 1", node2, testsuite.WithWalletBlockIssuanceCredits(wallet1BIC))
@@ -505,20 +511,13 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
505511
// MODIFY EXISTING GENESIS ACCOUNT
506512
var block1Slot iotago.SlotIndex = 1
507513
var latestParents []iotago.BlockID
508-
// The cost of the block that will make the account go negative.
509-
// We store it so we can allot that amount later to unlock it.
510-
block12ManaCost := iotago.Mana(0)
511514
// Issue one block from each of the two block-issuers - one will go negative and the other has enough BICs.
512515
{
513516
block1Commitment := iotago.NewEmptyCommitment(ts.API)
514517
block1Commitment.ReferenceManaCost = ts.API.ProtocolParameters().CongestionControlParameters().MinReferenceManaCost
515518
ts.SetCurrentSlot(block1Slot)
516-
block11 := ts.IssueBasicBlockWithOptions("block1.1", wallet1, &iotago.TaggedData{}, mock.WithSlotCommitment(block1Commitment))
517-
block12 := ts.IssueBasicBlockWithOptions("block1.2", wallet2, &iotago.TaggedData{}, mock.WithStrongParents(block11.ID()), mock.WithSlotCommitment(block1Commitment))
518-
519-
var err error
520-
block12ManaCost, err = block12.ProtocolBlock().ManaCost(block1Commitment.ReferenceManaCost)
521-
require.NoError(t, err)
519+
block11 := ts.IssueBasicBlockWithOptions("block1.1", wallet1, testPayload, mock.WithSlotCommitment(block1Commitment))
520+
block12 := ts.IssueBasicBlockWithOptions("block1.2", wallet2, testPayload, mock.WithStrongParents(block11.ID()), mock.WithSlotCommitment(block1Commitment))
522521

523522
// Commit BIC burns and check account states.
524523
ts.CommitUntilSlot(ts.BlockID("block1.2").Slot(), block12.ID())
@@ -552,9 +551,9 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
552551
{
553552
block2Commitment := node1.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Commitment()
554553

555-
block21 := ts.IssueBasicBlockWithOptions("block2.1", wallet1, &iotago.TaggedData{}, mock.WithSlotCommitment(block2Commitment))
554+
block21 := ts.IssueBasicBlockWithOptions("block2.1", wallet1, testPayload, mock.WithSlotCommitment(block2Commitment))
556555

557-
block22 := ts.IssueBasicBlockWithOptions("block2.2", wallet2, &iotago.TaggedData{}, mock.WithStrongParents(ts.BlockID("block2.1")), mock.WithSlotCommitment(block2Commitment))
556+
block22 := ts.IssueBasicBlockWithOptions("block2.2", wallet2, testPayload, mock.WithStrongParents(ts.BlockID("block2.1")), mock.WithSlotCommitment(block2Commitment))
558557

559558
ts.AssertBlockFiltered([]*blocks.Block{block22}, iotago.ErrAccountLocked, wallet2.Node)
560559

@@ -586,7 +585,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
586585
// Allot some mana to the locked account to unlock it.
587586
// The locked wallet 2 is preparing and signs the transaction, but it's issued by wallet 1 whose account is not locked.
588587
{
589-
allottedBIC := iotago.BlockIssuanceCredits(block12ManaCost)
588+
allottedBIC := testPayloadCost
590589
tx1 := wallet2.AllotManaFromInputs("TX1",
591590
iotago.Allotments{&iotago.Allotment{
592591
AccountID: wallet2.BlockIssuer.AccountID,
@@ -627,7 +626,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
627626
{
628627
block4Commitment := node1.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Commitment()
629628

630-
block4 := ts.IssueBasicBlockWithOptions("block4", wallet2, &iotago.TaggedData{}, mock.WithStrongParents(latestParents...), mock.WithSlotCommitment(block4Commitment))
629+
block4 := ts.IssueBasicBlockWithOptions("block4", wallet2, testPayload, mock.WithStrongParents(latestParents...), mock.WithSlotCommitment(block4Commitment))
631630

632631
ts.CommitUntilSlot(ts.BlockID("block4").Slot(), block4.ID())
633632

@@ -768,7 +767,17 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
768767
// Allot some mana to the locked account to unlock it.
769768
// The locked wallet 1 is preparing and signs the transaction, but it's issued by wallet 2 whose account is not locked.
770769
{
771-
allottedBIC := iotago.BlockIssuanceCredits(100_000_000)
770+
// create a dummy TX of the kind we want wallet 1 to issue next, so we can calculate it's cost.
771+
dummyTx := wallet1.TransitionAccount(
772+
"TX3",
773+
"Genesis:2",
774+
mock.WithAddBlockIssuerKey(newWallet1IssuerKey),
775+
mock.WithBlockIssuerExpirySlot(newExpirySlot),
776+
)
777+
dummyTxCost := iotago.BlockIssuanceCredits(lo.PanicOnErr(dummyTx.WorkScore(ts.API.ProtocolParameters().WorkScoreParameters()))) + iotago.BlockIssuanceCredits(ts.API.ProtocolParameters().CongestionControlParameters().MinReferenceManaCost)
778+
779+
// allot enough Mana to unlock the account AND cover the cost of the next transaction.
780+
allottedBIC := dummyTxCost + 1
772781
tx2 := wallet1.AllotManaFromInputs("TX2",
773782
iotago.Allotments{&iotago.Allotment{
774783
AccountID: wallet1.BlockIssuer.AccountID,

pkg/testsuite/mock/wallet.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,26 @@ func (w *Wallet) TransactionID(alias string) iotago.TransactionID {
121121
return lo.PanicOnErr(w.Transaction(alias).ID())
122122
}
123123

124-
func (w *Wallet) Address() iotago.DirectUnlockableAddress {
125-
address := w.keyManager.Address(iotago.AddressEd25519)
124+
func (w *Wallet) Address(index ...uint32) iotago.DirectUnlockableAddress {
125+
address := w.keyManager.Address(iotago.AddressEd25519, index...)
126126
//nolint:forcetypeassert
127127
return address.(*iotago.Ed25519Address)
128128
}
129129

130-
func (w *Wallet) ImplicitAccountCreationAddress() *iotago.ImplicitAccountCreationAddress {
131-
address := w.keyManager.Address(iotago.AddressImplicitAccountCreation)
130+
func (w *Wallet) ImplicitAccountCreationAddress(index ...uint32) *iotago.ImplicitAccountCreationAddress {
131+
address := w.keyManager.Address(iotago.AddressImplicitAccountCreation, index...)
132132
//nolint:forcetypeassert
133133
return address.(*iotago.ImplicitAccountCreationAddress)
134134
}
135135

136-
func (w *Wallet) HasAddress(address iotago.Address) bool {
137-
return address.Equal(w.Address()) || address.Equal(w.ImplicitAccountCreationAddress())
136+
func (w *Wallet) HasAddress(address iotago.Address, index ...uint32) bool {
137+
return address.Equal(w.Address(index...)) || address.Equal(w.ImplicitAccountCreationAddress(index...))
138138
}
139139

140140
func (w *Wallet) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey) {
141141
return w.keyManager.KeyPair()
142142
}
143143

144-
func (w *Wallet) AddressSigner() iotago.AddressSigner {
145-
return w.keyManager.AddressSigner()
144+
func (w *Wallet) AddressSigner(indexes ...uint32) iotago.AddressSigner {
145+
return w.keyManager.AddressSigner(indexes...)
146146
}

0 commit comments

Comments
 (0)