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

Unify wallet: Part 2 #889

Merged
merged 32 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0682e3e
use mock client in docker framework
cyberphysic4l Mar 20, 2024
b03dbd4
initialise wallet client correctly
cyberphysic4l Mar 20, 2024
6a361b0
unify wallets (with some bugs)
cyberphysic4l Mar 26, 2024
dcb9584
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Mar 26, 2024
e7211aa
delete docker wallet file
cyberphysic4l Mar 26, 2024
016f27a
fix merge errors
cyberphysic4l Mar 26, 2024
1ad981e
fix accounts docker test
cyberphysic4l Mar 27, 2024
49f675c
fix validators and core api tests
cyberphysic4l Mar 27, 2024
9b8befd
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Mar 27, 2024
19ba849
fix linter errors
cyberphysic4l Mar 27, 2024
da400f0
fix most of mqtt problems
cyberphysic4l Mar 28, 2024
3b03fbb
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Mar 28, 2024
17c1b8d
fix mqtt tests but with peering issue
cyberphysic4l Mar 28, 2024
e132677
fix nil pointer address
cyberphysic4l Mar 28, 2024
a596ff5
Daria comments
cyberphysic4l Mar 29, 2024
f17f25c
missing context
cyberphysic4l Mar 29, 2024
73fe3de
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Apr 17, 2024
ac51ff9
fix some merge errors
cyberphysic4l Apr 17, 2024
15a40c1
fix validator api test
cyberphysic4l Apr 17, 2024
65705fd
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Apr 17, 2024
9fb1368
fix mqtt tests
cyberphysic4l Apr 18, 2024
a8fcf8a
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Apr 18, 2024
c3edf61
merge fix
cyberphysic4l Apr 18, 2024
a8bf1c0
Fix validator rewards test
cyberphysic4l Apr 18, 2024
aacb493
fix delegation tests
cyberphysic4l Apr 19, 2024
f02704b
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Apr 19, 2024
a377a07
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Apr 22, 2024
3ec4141
Update pkg/testsuite/mock/wallet.go
cyberphysic4l Apr 23, 2024
8f651be
Update pkg/testsuite/mock/wallet.go
cyberphysic4l Apr 23, 2024
8081e16
review comments
cyberphysic4l Apr 23, 2024
cf3bc20
Add some descriptive names to blocks
cyberphysic4l Apr 23, 2024
37fea1b
Merge branch 'develop' into feat/unify-wallets2
cyberphysic4l Apr 23, 2024
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
7 changes: 4 additions & 3 deletions pkg/tests/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
block2Slot := ts.CurrentSlot()
tx2 := ts.DefaultWallet().CreateDelegationFromInput(
"TX2",
"TX1:1",
ts.DefaultWallet().OutputData("TX1:1"),
mock.WithDelegatedValidatorAddress(&accountAddress),
mock.WithDelegationStartEpoch(1),
)
Expand Down Expand Up @@ -304,7 +304,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {

// transition a delegation output to a delayed claiming state
block3Slot := ts.CurrentSlot()
tx3 := ts.DefaultWallet().DelayedClaimingTransition("TX3", "TX2:0", 0)
tx3 := ts.DefaultWallet().DelayedClaimingTransition("TX3", ts.DefaultWallet().OutputData("TX2:0"), 0)
block3 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block3", ts.DefaultWallet(), tx3, mock.WithStrongParents(latestParents...)))

latestParents = ts.CommitUntilSlot(block3Slot, block3.ID())
Expand Down Expand Up @@ -414,9 +414,10 @@ func Test_ImplicitAccounts(t *testing.T) {
fullAccountBlockIssuerKey := tpkg.RandBlockIssuerKey()

block2Slot := ts.CurrentSlot()
implicitAccountData := newUserWallet.OutputData("TX1:0")
tx2 := newUserWallet.TransitionImplicitAccountToAccountOutput(
"TX2",
[]string{"TX1:0"},
[]*mock.OutputData{implicitAccountData},
mock.WithBlockIssuerFeature(
iotago.BlockIssuerKeys{fullAccountBlockIssuerKey},
iotago.MaxSlotIndex,
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/booker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func Test_BlockWithInvalidTransactionGetsBooked(t *testing.T) {
var block1Slot iotago.SlotIndex = ts.API.ProtocolParameters().GenesisSlot() + 1
ts.SetCurrentSlot(block1Slot)

tx1 := ts.DefaultWallet().CreateNFTFromInput("TX1", "Genesis:0",
tx1 := ts.DefaultWallet().CreateNFTFromInput("TX1", ts.DefaultWallet().OutputData("Genesis:0"),
func(nftBuilder *builder.NFTOutputBuilder) {
// Set an issuer ID that is not unlocked in the TX which will cause the TX to be invalid.
nftBuilder.ImmutableIssuer(&iotago.Ed25519Address{})
Expand Down
4 changes: 3 additions & 1 deletion pkg/tests/combined_account_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ func createImplicitToFullAccount(ts *testsuite.TestSuite) iotago.AccountID {

// TRANSITION IMPLICIT ACCOUNT TO ACCOUNT OUTPUT.
block3Slot := ts.CurrentSlot()
implicitAccoutData := newUserWallet.OutputData("TX3:0")
basicOutputData := newUserWallet.OutputData("TX3:1")
tx4 := newUserWallet.TransitionImplicitAccountToAccountOutput(
"TX4",
[]string{"TX3:0", "TX3:1"},
[]*mock.OutputData{implicitAccoutData, basicOutputData},
mock.WithBlockIssuerFeature(
iotago.BlockIssuerKeys{implicitBlockIssuerKey},
iotago.MaxSlotIndex,
Expand Down
34 changes: 17 additions & 17 deletions pkg/tests/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Test_Delegation_DestroyOutputWithoutRewards(t *testing.T) {
ts.SetCurrentSlot(block1Slot)
tx1 := ts.DefaultWallet().CreateDelegationFromInput(
"TX1",
"Genesis:0",
ts.DefaultWallet().OutputData("Genesis:0"),
mock.WithDelegatedValidatorAddress(accountAddress),
mock.WithDelegationStartEpoch(1),
)
Expand All @@ -84,7 +84,7 @@ func Test_Delegation_DestroyOutputWithoutRewards(t *testing.T) {
latestParents := ts.CommitUntilSlot(block1Slot, block1.ID())

block2Slot := ts.CurrentSlot()
tx2 := ts.DefaultWallet().ClaimDelegatorRewards("TX2", "TX1:0")
tx2 := ts.DefaultWallet().ClaimDelegatorRewards("TX2", ts.DefaultWallet().OutputData("TX1:0"))
block2 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block2", ts.DefaultWallet(), tx2, mock.WithStrongParents(latestParents...)))

ts.CommitUntilSlot(block2Slot, block2.ID())
Expand All @@ -103,7 +103,7 @@ func Test_Delegation_DelayedClaimingDestroyOutputWithoutRewards(t *testing.T) {
ts.SetCurrentSlot(block1_2Slot)
tx1 := ts.DefaultWallet().CreateDelegationFromInput(
"TX1",
"Genesis:0",
ts.DefaultWallet().OutputData("Genesis:0"),
mock.WithDelegatedValidatorAddress(accountAddress),
mock.WithDelegationStartEpoch(1),
)
Expand All @@ -124,13 +124,13 @@ func Test_Delegation_DelayedClaimingDestroyOutputWithoutRewards(t *testing.T) {
delegationEndEpoch = futureBoundedEpochIndex + 1
}

tx2 := ts.DefaultWallet().DelayedClaimingTransition("TX2", "TX1:0", delegationEndEpoch)
tx2 := ts.DefaultWallet().DelayedClaimingTransition("TX2", ts.DefaultWallet().OutputData("TX1:0"), delegationEndEpoch)
block2 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block2", ts.DefaultWallet(), tx2, mock.WithStrongParents(block1.ID())))
latestParents := ts.CommitUntilSlot(block1_2Slot, block2.ID())

// CLAIM ZERO REWARDS
block3Slot := ts.CurrentSlot()
tx3 := ts.DefaultWallet().ClaimDelegatorRewards("TX3", "TX2:0")
tx3 := ts.DefaultWallet().ClaimDelegatorRewards("TX3", ts.DefaultWallet().OutputData("TX2:0"))
block3 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block3", ts.DefaultWallet(), tx3, mock.WithStrongParents(latestParents...)))

ts.CommitUntilSlot(block3Slot, block3.ID())
Expand Down Expand Up @@ -183,7 +183,7 @@ func Test_Account_RemoveStakingFeatureWithoutRewards(t *testing.T) {

// REMOVE STAKING FEATURE AND CLAIM ZERO REWARDS
block2Slot := ts.CurrentSlot()
tx2 := ts.DefaultWallet().ClaimValidatorRewards("TX2", "TX1:0")
tx2 := ts.DefaultWallet().ClaimValidatorRewards("TX2", ts.DefaultWallet().OutputData("TX1:0"))
block2 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block2", ts.DefaultWallet(), tx2, mock.WithStrongParents(latestParents...)))

ts.CommitUntilSlot(block2Slot, block2.ID())
Expand Down Expand Up @@ -227,7 +227,7 @@ func Test_RewardInputCannotPointToNFTOutput(t *testing.T) {
var block1Slot iotago.SlotIndex = 1
ts.SetCurrentSlot(block1Slot)

tx1 := ts.DefaultWallet().CreateNFTFromInput("TX1", "Genesis:0")
tx1 := ts.DefaultWallet().CreateNFTFromInput("TX1", ts.DefaultWallet().OutputData("Genesis:0"))
block1 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block1", ts.DefaultWallet(), tx1))

latestParents := ts.CommitUntilSlot(block1Slot, block1.ID())
Expand Down Expand Up @@ -301,7 +301,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {
blockIssuanceResp := ts.DefaultWallet().GetNewBlockIssuanceResponse()
tx2 := ts.DefaultWallet().CreateDelegationFromInput(
"TX2",
"TX1:1",
ts.DefaultWallet().OutputData("TX1:1"),
mock.WithDelegationAmount(deleg1),
mock.WithDelegatedAmount(deleg1),
mock.WithDelegatedValidatorAddress(&accountAddress),
Expand All @@ -326,7 +326,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {
// Create another delegation.
tx4 := ts.DefaultWallet().CreateDelegationFromInput(
"TX4",
"TX2:1",
ts.DefaultWallet().OutputData("TX2:1"),
mock.WithDelegationAmount(deleg2),
mock.WithDelegatedAmount(deleg2),
mock.WithDelegatedValidatorAddress(&accountAddress),
Expand All @@ -343,15 +343,15 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {
blockIssuanceResp = ts.DefaultWallet().GetNewBlockIssuanceResponse()
tx5 := ts.DefaultWallet().CreateDelegationFromInput(
"TX5",
"TX4:1",
ts.DefaultWallet().OutputData("TX4:1"),
mock.WithDelegationAmount(deleg3),
mock.WithDelegatedAmount(deleg3),
mock.WithDelegatedValidatorAddress(&accountAddress),
mock.WithDelegationStartEpoch(ts.DefaultWallet().DelegationStartFromSlot(block5_6Slot, blockIssuanceResp.LatestCommitment.Slot)),
)
block5 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block5", ts.DefaultWallet(), tx5, mock.WithStrongParents(latestParents...)))
blockIssuanceResp = ts.DefaultWallet().GetNewBlockIssuanceResponse()
tx6 := ts.DefaultWallet().DelayedClaimingTransition("TX6", "TX5:0", ts.DefaultWallet().DelegationEndFromSlot(block5_6Slot, blockIssuanceResp.LatestCommitment.Slot))
tx6 := ts.DefaultWallet().DelayedClaimingTransition("TX6", ts.DefaultWallet().OutputData("TX5:0"), ts.DefaultWallet().DelegationEndFromSlot(block5_6Slot, blockIssuanceResp.LatestCommitment.Slot))
block6 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block6", ts.DefaultWallet(), tx6, mock.WithStrongParents(block5.ID())))

latestParents = ts.CommitUntilSlot(block5_6Slot, block6.ID())
Expand All @@ -365,7 +365,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {
blockIssuanceResp = ts.DefaultWallet().GetNewBlockIssuanceResponse()
tx7 := ts.DefaultWallet().CreateDelegationFromInput(
"TX7",
"TX5:1",
ts.DefaultWallet().OutputData("TX5:1"),
mock.WithDelegationAmount(deleg4),
mock.WithDelegatedAmount(deleg4),
mock.WithDelegatedValidatorAddress(&accountAddress),
Expand All @@ -375,7 +375,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {

latestParents = ts.CommitUntilSlot(block7_8Slot, block7.ID())

tx8 := ts.DefaultWallet().ClaimDelegatorRewards("TX8", "TX7:0")
tx8 := ts.DefaultWallet().ClaimDelegatorRewards("TX8", ts.DefaultWallet().OutputData("TX7:0"))
block8 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block8", ts.DefaultWallet(), tx8, mock.WithStrongParents(latestParents...)))

block8Slot := ts.CurrentSlot()
Expand All @@ -387,7 +387,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {
// STEP 6: REMOVE A DELEGATION BY TRANSITIONING TO DELAYED CLAIMING.
block9Slot := ts.CurrentSlot()
blockIssuanceResp = ts.DefaultWallet().GetNewBlockIssuanceResponse()
tx9 := ts.DefaultWallet().DelayedClaimingTransition("TX9", "TX4:0", ts.DefaultWallet().DelegationEndFromSlot(block9Slot, blockIssuanceResp.LatestCommitment.Slot))
tx9 := ts.DefaultWallet().DelayedClaimingTransition("TX9", ts.DefaultWallet().OutputData("TX4:0"), ts.DefaultWallet().DelegationEndFromSlot(block9Slot, blockIssuanceResp.LatestCommitment.Slot))
block9 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block9", ts.DefaultWallet(), tx9, mock.WithStrongParents(latestParents...)))
// Commit until the claiming epoch so we can remove the staking feature from the account in the next step.
latestParents = ts.CommitUntilSlot(block9Slot, block9.ID())
Expand All @@ -396,7 +396,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {

// STEP 7: DESTROY THE DELEGATION IN DELAYED CLAIMING STATE
// This is to ensure the delegated stake is not subtracted twice from the account.
tx10 := ts.DefaultWallet().ClaimDelegatorRewards("TX19", "TX9:0")
tx10 := ts.DefaultWallet().ClaimDelegatorRewards("TX19", ts.DefaultWallet().OutputData("TX9:0"))
block10 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block10", ts.DefaultWallet(), tx10, mock.WithStrongParents(latestParents...)))

// Commit until the claiming epoch so we can remove the staking feature from the account in the next step.
Expand All @@ -406,7 +406,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {

// STEP 8: DESTROY ACCOUNT.
block11Slot := ts.CurrentSlot()
tx11 := ts.DefaultWallet().ClaimValidatorRewards("TX11", "TX3:0")
tx11 := ts.DefaultWallet().ClaimValidatorRewards("TX11", ts.DefaultWallet().OutputData("TX3:0"))
block11 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block11", ts.DefaultWallet(), tx11, mock.WithStrongParents(latestParents...)))
latestParents = ts.CommitUntilSlot(block11Slot, block11.ID())

Expand All @@ -418,7 +418,7 @@ func Test_Account_StakeAmountCalculation(t *testing.T) {

block12Slot := ts.CurrentSlot()
blockIssuanceResp = ts.DefaultWallet().GetNewBlockIssuanceResponse()
tx12 := ts.DefaultWallet().DelayedClaimingTransition("TX12", "TX2:0", ts.DefaultWallet().DelegationEndFromSlot(block12Slot, blockIssuanceResp.LatestCommitment.Slot))
tx12 := ts.DefaultWallet().DelayedClaimingTransition("TX12", ts.DefaultWallet().OutputData("TX2:0"), ts.DefaultWallet().DelegationEndFromSlot(block12Slot, blockIssuanceResp.LatestCommitment.Slot))
block12 := lo.PanicOnErr(ts.IssueBasicBlockWithOptions("block12", ts.DefaultWallet(), tx12, mock.WithStrongParents(latestParents...)))
ts.CommitUntilSlot(block12Slot, block12.ID())

Expand Down
6 changes: 3 additions & 3 deletions pkg/testsuite/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func (t *TestSuite) AssertBlock(block *blocks.Block, client mock.Client) *iotago
var err error
loadedBlock, err = client.BlockByBlockID(context.Background(), block.ID())
if err != nil {
return ierrors.Wrapf(err, "AssertBlock: %s: block %s does not exist", client.Name(), block.ID())
return ierrors.Wrapf(err, "AssertBlock: block %s does not exist", block.ID())
}

if block.ID() != loadedBlock.MustID() {
return ierrors.Errorf("AssertBlock: %s: expected %s, got %s", client.Name(), block.ID(), loadedBlock.MustID())
return ierrors.Errorf("AssertBlock: expected %s, got %s", block.ID(), loadedBlock.MustID())
}

return nil
Expand All @@ -43,7 +43,7 @@ func (t *TestSuite) AssertBlocksExist(blocks []*blocks.Block, expectedExist bool
t.Eventually(func() error {
_, err := client.BlockByBlockID(context.Background(), block.ID())
if err == nil {
return ierrors.Errorf("AssertBlocksExist: %s: block %s exists but should not", client.Name(), block)
return ierrors.Errorf("AssertBlocksExist: block %s exists but should not", block)
}

return nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/testsuite/mock/block_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ type ValidationBlockParams struct {
ProtocolParametersHash *iotago.Identifier
}

func NewValidationBlockParams() *ValidationBlockParams {
return &ValidationBlockParams{
BlockHeader: &BlockHeaderParams{},
}
}

func WithParentsCount(parentsCount int) func(builder *BlockHeaderParams) {
return func(builder *BlockHeaderParams) {
builder.ParentsCount = parentsCount
Expand Down
51 changes: 24 additions & 27 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,18 @@ type BlockIssuer struct {
blockIssuanceResponseUsed bool
mutex syncutils.RWMutex

AccountData AccountData
AccountData *AccountData
}

func NewBlockIssuer(t *testing.T, name string, keyManager *wallet.KeyManager, client Client, addressIndex uint32, accountID iotago.AccountID, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer {
func NewBlockIssuer(t *testing.T, name string, keyManager *wallet.KeyManager, client Client, accountData *AccountData, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer {
t.Helper()

_, pub := keyManager.KeyPair(addressIndex)
_, pub := keyManager.KeyPair(accountData.AddressIndex)

if accountID == iotago.EmptyAccountID {
accountID = blake2b.Sum256(pub)
if accountData.ID == iotago.EmptyAccountID {
accountData.ID = blake2b.Sum256(pub)
}
accountID.RegisterAlias(name)

accountAddress, ok := accountID.ToAddress().(*iotago.AccountAddress)
require.True(t, ok)
accountData.ID.RegisterAlias(name)

return options.Apply(&BlockIssuer{
Testing: t,
Expand All @@ -74,11 +71,7 @@ func NewBlockIssuer(t *testing.T, name string, keyManager *wallet.KeyManager, cl
keyManager: keyManager,
Client: client,
blockIssuanceResponseUsed: true,
AccountData: AccountData{
ID: accountID,
AddressIndex: addressIndex,
Address: accountAddress,
},
AccountData: accountData,
}, opts)
}

Expand All @@ -96,8 +89,10 @@ func (i *BlockIssuer) Address() iotago.Address {
return iotago.Ed25519AddressFromPubKey(pub)
}

// CreateValidationBlock creates a new validation block with the options provided. If a node is specified, it will try to
// revive the chain if the block is too far behind the latest commitment.
func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[ValidationBlockParams]) (*blocks.Block, error) {
blockParams := options.Apply(&ValidationBlockParams{}, opts)
blockParams := options.Apply(NewValidationBlockParams(), opts)

if blockParams.BlockHeader.IssuingTime == nil {
issuingTime := time.Now().UTC()
Expand All @@ -111,7 +106,7 @@ func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, n
if blockParams.BlockHeader.SlotCommitment == nil {
commitment := blockIssuanceInfo.LatestCommitment
blockSlot := apiForBlock.TimeProvider().SlotFromTime(*blockParams.BlockHeader.IssuingTime)
if blockSlot > commitment.Slot+protoParams.MaxCommittableAge() {
if blockSlot > commitment.Slot+protoParams.MaxCommittableAge() && node != nil {
var parentID iotago.BlockID
var err error
commitment, parentID, err = i.reviveChain(*blockParams.BlockHeader.IssuingTime, node)
Expand Down Expand Up @@ -202,7 +197,7 @@ func referencesFromBlockIssuanceResponse(response *api.IssuanceBlockHeaderRespon
return references
}

func (i *BlockIssuer) IssueValidationBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[ValidationBlockParams]) (*blocks.Block, error) {
func (i *BlockIssuer) CreateAndSubmitValidationBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[ValidationBlockParams]) (*blocks.Block, error) {
block, err := i.CreateValidationBlock(ctx, alias, node, opts...)
require.NoError(i.Testing, err)

Expand All @@ -215,10 +210,6 @@ func (i *BlockIssuer) IssueValidationBlock(ctx context.Context, alias string, no
func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts ...options.Option[BasicBlockParams]) (*blocks.Block, error) {
blockParams := options.Apply(&BasicBlockParams{BlockHeader: &BlockHeaderParams{}}, opts)

if blockParams.BlockHeader.IssuingTime == nil {
issuingTime := time.Now().UTC()
blockParams.BlockHeader.IssuingTime = &issuingTime
}
blockIssuanceInfo := i.latestBlockIssuanceResponse(ctx)

if blockParams.BlockHeader.References == nil {
Expand All @@ -233,7 +224,6 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts .

blockBuilder.SlotCommitmentID(blockParams.BlockHeader.SlotCommitment.MustID())
blockBuilder.LatestFinalizedSlot(*blockParams.BlockHeader.LatestFinalizedSlot)
blockBuilder.IssuingTime(*blockParams.BlockHeader.IssuingTime)
strongParents, exists := blockParams.BlockHeader.References[iotago.StrongParentType]
require.True(i.Testing, exists && len(strongParents) > 0, "block should have strong parents (exists: %t, parents: %s)", exists, strongParents)
blockBuilder.StrongParents(strongParents)
Expand All @@ -251,6 +241,13 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts .
// use the rmc corresponding to the commitment used in the block
blockBuilder.CalculateAndSetMaxBurnedMana(blockIssuanceInfo.LatestCommitment.ReferenceManaCost)

// set the issuing time last to ensure the timestamp is greater than that of the parents selected.
if blockParams.BlockHeader.IssuingTime == nil {
issuingTime := time.Now().UTC()
blockParams.BlockHeader.IssuingTime = &issuingTime
}
blockBuilder.IssuingTime(*blockParams.BlockHeader.IssuingTime)

priv, _ := i.keyManager.KeyPair(i.AccountData.AddressIndex)
blockBuilder.Sign(i.AccountData.ID, priv)

Expand All @@ -263,10 +260,13 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts .

modelBlock.ID().RegisterAlias(alias)

// mark the response as used so that the next time we query the node for the latest block issuance.
i.blockIssuanceResponseUsed = true

return blocks.NewBlock(modelBlock), err
}

func (i *BlockIssuer) IssueBasicBlock(ctx context.Context, alias string, opts ...options.Option[BasicBlockParams]) (*blocks.Block, error) {
func (i *BlockIssuer) CreateAndSubmitBasicBlock(ctx context.Context, alias string, opts ...options.Option[BasicBlockParams]) (*blocks.Block, error) {
block, err := i.CreateBasicBlock(ctx, alias, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -295,7 +295,7 @@ func (i *BlockIssuer) IssueActivity(ctx context.Context, wg *sync.WaitGroup, sta

blockAlias := fmt.Sprintf("%s-activity.%d", i.Name, counter)
timeOffset := time.Since(start)
lo.PanicOnErr(i.IssueValidationBlock(ctx, blockAlias, node,
lo.PanicOnErr(i.CreateAndSubmitValidationBlock(ctx, blockAlias, node,
WithValidationBlockHeaderOptions(
WithIssuingTime(issuingTime.Add(timeOffset)),
),
Expand Down Expand Up @@ -361,9 +361,6 @@ func (i *BlockIssuer) SubmitBlock(ctx context.Context, block *model.Block) error
i.mutex.Lock()
defer i.mutex.Unlock()

// mark the response as used so that the next time we query the node for the latest block issuance.
i.blockIssuanceResponseUsed = true

return lo.Return2(i.Client.SubmitBlock(ctx, block.ProtocolBlock()))
}

Expand Down
Loading
Loading