Skip to content

Commit

Permalink
Merge pull request #967 from iotaledger/fix/speedup-docker-tests
Browse files Browse the repository at this point in the history
Speedup docker tests
  • Loading branch information
muXxer authored May 17, 2024
2 parents 104870d + 64f0f73 commit 4cce1bd
Show file tree
Hide file tree
Showing 25 changed files with 1,314 additions and 946 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,19 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) {
return
}

blockEpoch := o.apiProvider.APIForSlot(block.ID().Slot()).TimeProvider().EpochFromSlot(block.ID().Slot())
blockSlot := block.ID().Slot()
blockAPI := o.apiProvider.APIForSlot(blockSlot)
blockEpoch := blockAPI.TimeProvider().EpochFromSlot(blockSlot)

// if the block is issued before the stake end epoch, then it's not a valid validator or candidate block
if accountData.StakeEndEpoch() < blockEpoch {
// if the block is issued in or after the stake end epoch,
// then don't consider it because the validator can't be part of the committee in the next epoch.
if blockEpoch >= accountData.StakeEndEpoch() {
return
}

// if a candidate block is issued in the stake end epoch,
// or if block is issued after EpochEndSlot - EpochNearingThreshold, because candidates can register only until that point.
// then don't consider it because the validator can't be part of the committee in the next epoch
if accountData.StakeEndEpoch() == blockEpoch ||
block.ID().Slot()+o.apiProvider.APIForSlot(block.ID().Slot()).ProtocolParameters().EpochNearingThreshold() > o.apiProvider.APIForSlot(block.ID().Slot()).TimeProvider().EpochEnd(blockEpoch) {
// if block is issued after EpochEndSlot - EpochNearingThreshold, because candidates can register only until that point.
// then also don't consider it because the validator can't be part of the committee in the next epoch.
if blockSlot+blockAPI.ProtocolParameters().EpochNearingThreshold() > blockAPI.TimeProvider().EpochEnd(blockEpoch) {
return
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/tests/combined_account_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@ func Test_AccountStateTransition(t *testing.T) {
ts.AssertTransactionsInCacheAccepted(wallet.Transactions("TX1"), true, node1, node2)
}

// create the account1 from TX1:0 with wallet "first"
// create the account-1 from TX1:0 with wallet "account-1"
// generated (block1, TX2)
ts.AddWallet("first", node1, iotago.EmptyAccountID)
ts.AddWallet("account-1", node1, iotago.EmptyAccountID)
createFullAccount(ts)

// create the account2, from implicit to full account from TX1:1 with wallet "second"
// create the account-2, from implicit to full account from TX1:1 with wallet "account-2"
// generated (block2, TX3), (block3, TX4)
ts.AddWallet("second", node1, iotago.EmptyAccountID)
ts.AddWallet("account-2", node1, iotago.EmptyAccountID)
account2ID := createImplicitToFullAccount(ts)

// send funds to account2, with TX1:2
// send funds to account-2, with TX1:2
// generated (block4, TX5)
sendFunds(ts)

// allot 1000 mana to account2 with TX1:3
// allot 1000 mana to account-2 with TX1:3
// generated (block5, TX6)
allotManaTo(ts, account2ID)

// create native token from "TX5:0" and account2 (TX4:0)
// create native token from "TX5:0" and account-2 (TX4:0)
// generated (block6, TX7)
createNativetoken(ts)
}

func createFullAccount(ts *testsuite.TestSuite) iotago.AccountID {
node1 := ts.Node("node1")
newUserWallet := ts.Wallet("first")
newUserWallet := ts.Wallet("account-1")

// CREATE NEW ACCOUNT WITH BLOCK ISSUER FROM BASIC UTXO
newAccountBlockIssuerKey := tpkg.RandBlockIssuerKey()
Expand Down Expand Up @@ -125,7 +125,7 @@ func createFullAccount(ts *testsuite.TestSuite) iotago.AccountID {

func createImplicitToFullAccount(ts *testsuite.TestSuite) iotago.AccountID {
node1 := ts.Node("node1")
newUserWallet := ts.Wallet("second")
newUserWallet := ts.Wallet("account-2")

// CREATE IMPLICIT ACCOUNT FROM GENESIS BASIC UTXO, SENT TO A NEW USER WALLET.
// a default wallet, already registered in the ledger, will issue the transaction and block.
Expand Down Expand Up @@ -198,7 +198,7 @@ func sendFunds(ts *testsuite.TestSuite) {
node1 := ts.Node("node1")
node2 := ts.Node("node2")
wallet := ts.DefaultWallet()
secondWallet := ts.Wallet("second")
secondWallet := ts.Wallet("account-2")

// send funds from defaultWallet to secondWallet
tx := wallet.SendFundsToWallet("TX5", secondWallet, "TX1:2")
Expand Down Expand Up @@ -246,7 +246,7 @@ func allotManaTo(ts *testsuite.TestSuite, to iotago.AccountID) {

// createNativetoken creates a native token from the given input and account.
func createNativetoken(ts *testsuite.TestSuite) {
wallet := ts.Wallet("second")
wallet := ts.Wallet("account-2")
node1 := ts.Node("node1")
node2 := ts.Node("node2")

Expand Down
51 changes: 11 additions & 40 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ type BlockIssuer struct {
keyManager *wallet.KeyManager
Client Client

// latestBlockIssuanceResp is the cached response from the latest query to the block issuance endpoint.
latestBlockIssuanceResp *api.IssuanceBlockHeaderResponse
blockIssuanceResponseUsed bool
mutex syncutils.RWMutex
mutex syncutils.RWMutex

AccountData *AccountData
}
Expand All @@ -65,13 +62,12 @@ func NewBlockIssuer(t *testing.T, name string, keyManager *wallet.KeyManager, cl
accountData.ID.RegisterAlias(name)

return options.Apply(&BlockIssuer{
Testing: t,
Name: name,
Validator: validator,
keyManager: keyManager,
Client: client,
blockIssuanceResponseUsed: true,
AccountData: accountData,
Testing: t,
Name: name,
Validator: validator,
keyManager: keyManager,
Client: client,
AccountData: accountData,
}, opts)
}

Expand Down Expand Up @@ -216,13 +212,14 @@ func (i *BlockIssuer) CreateAndSubmitValidationBlock(ctx context.Context, alias
func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, opts ...options.Option[BasicBlockParams]) (*blocks.Block, error) {
blockParams := options.Apply(&BasicBlockParams{BlockHeader: &BlockHeaderParams{}}, opts)

blockIssuanceInfo := i.latestBlockIssuanceResponse(ctx)
blockIssuanceInfo, err := i.Client.BlockIssuance(ctx)
require.NoError(i.Testing, err)

if blockParams.BlockHeader.References == nil {
blockParams.BlockHeader.References = referencesFromBlockIssuanceResponse(blockIssuanceInfo)
}

err := i.setDefaultBlockParams(ctx, blockParams.BlockHeader)
err = i.setDefaultBlockParams(ctx, blockParams.BlockHeader)
require.NoError(i.Testing, err)

api := i.Client.APIForTime(*blockParams.BlockHeader.IssuingTime)
Expand Down Expand Up @@ -270,9 +267,6 @@ 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
}

Expand Down Expand Up @@ -405,31 +399,8 @@ func (i *BlockIssuer) retrieveAPI(blockParams *BlockHeaderParams) iotago.API {
}

func (i *BlockIssuer) GetNewBlockIssuanceResponse() *api.IssuanceBlockHeaderResponse {
i.mutex.Lock()
defer i.mutex.Unlock()

i.blockIssuanceResponseUsed = false
resp, err := i.Client.BlockIssuance(context.Background())
require.NoError(i.Testing, err)
i.latestBlockIssuanceResp = resp

return i.latestBlockIssuanceResp
}

func (i *BlockIssuer) latestBlockIssuanceResponse(context context.Context) *api.IssuanceBlockHeaderResponse {
i.mutex.Lock()
defer i.mutex.Unlock()

// If the response was already used to issue a block, we need to get a new response from the node.
// Otherwise we can reuse the cached response. For transactions with commitment inputs, we want to get a fresh response
// for the transaction creation, and then reuse that response for the block issuance, so we only mark the response as used
// if it was used for block issuance.
if i.blockIssuanceResponseUsed {
i.blockIssuanceResponseUsed = false
resp, err := i.Client.BlockIssuance(context)
require.NoError(i.Testing, err)
i.latestBlockIssuanceResp = resp
}

return i.latestBlockIssuanceResp
return resp
}
25 changes: 25 additions & 0 deletions pkg/testsuite/mock/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ func NewAccountData(accountID iotago.AccountID, optAddressIndex ...uint32) *Acco
}
}

type AccountWithWallet struct {
account *AccountData
wallet *Wallet
}

func NewAccountWithWallet(account *AccountData, wallet *Wallet) *AccountWithWallet {
return &AccountWithWallet{
account: account,
wallet: wallet,
}
}

func (a *AccountWithWallet) Account() *AccountData {
return a.account
}

func (a *AccountWithWallet) UpdateAccount(updatedAccount *AccountData) {
a.account = updatedAccount
a.wallet.SetBlockIssuer(updatedAccount)
}

func (a *AccountWithWallet) Wallet() *Wallet {
return a.wallet
}

// WalletClock is an interface that provides the current slot.
type WalletClock interface {
SetCurrentSlot(slot iotago.SlotIndex)
Expand Down
7 changes: 1 addition & 6 deletions tools/docker-network/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ COMMON_CONFIG="
--profiling.bindAddress=0.0.0.0:6061
--restAPI.publicRoutes=/health,/api/routes,/api/core/v3/info,/api/core/v3/network*,/api/core/v3/blocks*,/api/core/v3/transactions*,/api/core/v3/commitments*,/api/core/v3/outputs*,/api/core/v3/accounts*,/api/core/v3/validators*,/api/core/v3/rewards*,/api/core/v3/committee*,/api/debug/v2/*,/api/indexer/v2/*,/api/mqtt/v2,/api/blockissuer/v1/*,/api/management/v1/*
--debugAPI.enabled=false
--p2p.autopeering.maxPeers=5
--p2p.autopeering.allowLocalIPs=true
"

AUTOPEERING_CONFIG="
--p2p.autopeering.bootstrapPeers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK
--p2p.autopeering.maxPeers=0
"

# admin/admin
Expand Down
21 changes: 16 additions & 5 deletions tools/docker-network/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
--db.path==${DB_PATH_V1:-/app/data/database}
--protocol.snapshot.path=${SNAPSHOT_PATH_V1:-/app/data/snapshots/snapshot.bin}
--p2p.identityPrivateKey=08735375679f3d8031353e94282ed1d65119e5c288fe56d6639d9184a3f978fee8febfedff11cc376daea0f59c395ae2e9a870a25ac4e36093000fbf4d0e8f18
--p2p.peers=/dns/node-2-validator/tcp/15600/p2p/12D3KooWCropDmzpoLy8UrFg59M1oUx7k1UmQmuHrmN5RDgp6pVL,/dns/node-3-validator/tcp/15600/p2p/12D3KooWPr1mW33PGhv3oRbPQQDesN4THBB3WgnYsNzCfnQLr5QR,/dns/node-4-validator/tcp/15600/p2p/12D3KooWRxDSg2H7ThEJyn4HNkL1ixsqm6PgjCtkTG1hm7NpYG4Q,/dns/node-5/tcp/15600/p2p/12D3KooWG9S868XrL1wzeUbMXDtBTAaxwuqktAzUodFFES8uoTGz,/dns/node-6/tcp/15600/p2p/12D3KooWFatFVM1wyGnMUwJrMW7YwD6j32iq5SCA9S7e386biZ73
--p2p.peerAliases=node-2-validator,node-3-validator,node-4-validator,node-5,node-6
--node.alias=node-1-validator
--inx.enabled=true
--inx.bindAddress=0.0.0.0:9029
Expand Down Expand Up @@ -62,10 +64,11 @@ services:
- ./config.json:/app/config.json:ro
command: >
${COMMON_CONFIG}
${AUTOPEERING_CONFIG}
--db.path==${DB_PATH_V2:-/app/data/database}
--protocol.snapshot.path=${SNAPSHOT_PATH_V2:-/app/data/snapshots/snapshot.bin}
--p2p.identityPrivateKey=ba771419c52132a0dfb2521ed18667813f398da159010a55a0a482af939affb92d3338789ad4a07a7631b91791deb11f82ed5dc612822f24275e9f7a313b691f
--p2p.peers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK,/dns/node-3-validator/tcp/15600/p2p/12D3KooWPr1mW33PGhv3oRbPQQDesN4THBB3WgnYsNzCfnQLr5QR,/dns/node-4-validator/tcp/15600/p2p/12D3KooWRxDSg2H7ThEJyn4HNkL1ixsqm6PgjCtkTG1hm7NpYG4Q,/dns/node-5/tcp/15600/p2p/12D3KooWG9S868XrL1wzeUbMXDtBTAaxwuqktAzUodFFES8uoTGz,/dns/node-6/tcp/15600/p2p/12D3KooWFatFVM1wyGnMUwJrMW7YwD6j32iq5SCA9S7e386biZ73
--p2p.peerAliases=node-1-validator,node-3-validator,node-4-validator,node-5,node-6
--node.alias=node-2-validator
--inx.enabled=true
--inx.bindAddress=0.0.0.0:9029
Expand Down Expand Up @@ -96,10 +99,11 @@ services:
- ./config.json:/app/config.json:ro
command: >
${COMMON_CONFIG}
${AUTOPEERING_CONFIG}
--db.path==${DB_PATH_V3:-/app/data/database}
--protocol.snapshot.path=${SNAPSHOT_PATH_V3:-/app/data/snapshots/snapshot.bin}
--p2p.identityPrivateKey=a6261ac049755675ff1437654ca9f83b305055f01ff08c4f039209ef5a4a7d96d06fb61df77a8815209a8f4d204226dee593e50d0ec897ec440a2c1fbde77656
--p2p.peers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK,/dns/node-2-validator/tcp/15600/p2p/12D3KooWCropDmzpoLy8UrFg59M1oUx7k1UmQmuHrmN5RDgp6pVL,/dns/node-4-validator/tcp/15600/p2p/12D3KooWRxDSg2H7ThEJyn4HNkL1ixsqm6PgjCtkTG1hm7NpYG4Q,/dns/node-5/tcp/15600/p2p/12D3KooWG9S868XrL1wzeUbMXDtBTAaxwuqktAzUodFFES8uoTGz,/dns/node-6/tcp/15600/p2p/12D3KooWFatFVM1wyGnMUwJrMW7YwD6j32iq5SCA9S7e386biZ73
--p2p.peerAliases=node-1-validator,node-2-validator,node-4-validator,node-5,node-6
--node.alias=node-3-validator
--inx.enabled=true
--inx.bindAddress=0.0.0.0:9029
Expand Down Expand Up @@ -130,10 +134,11 @@ services:
- ./config.json:/app/config.json:ro
command: >
${COMMON_CONFIG}
${AUTOPEERING_CONFIG}
--db.path==${DB_PATH_V4:-/app/data/database}
--protocol.snapshot.path=${SNAPSHOT_PATH_V4:-/app/data/snapshots/snapshot.bin}
--p2p.identityPrivateKey=f205f6c4525069f71f9c7e987d72421a16c7900056b494a2b85fdf7942cf906aefbdc580f5d1ce4ae3f86ccfe109c6cd76df9b0e710a437b2aa964358c7b9449
--p2p.peers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK,/dns/node-2-validator/tcp/15600/p2p/12D3KooWCropDmzpoLy8UrFg59M1oUx7k1UmQmuHrmN5RDgp6pVL,/dns/node-3-validator/tcp/15600/p2p/12D3KooWPr1mW33PGhv3oRbPQQDesN4THBB3WgnYsNzCfnQLr5QR,/dns/node-5/tcp/15600/p2p/12D3KooWG9S868XrL1wzeUbMXDtBTAaxwuqktAzUodFFES8uoTGz,/dns/node-6/tcp/15600/p2p/12D3KooWFatFVM1wyGnMUwJrMW7YwD6j32iq5SCA9S7e386biZ73
--p2p.peerAliases=node-1-validator,node-2-validator,node-3-validator,node-5,node-6
--node.alias=node-4-validator
--inx.enabled=true
--inx.bindAddress=0.0.0.0:9029
Expand Down Expand Up @@ -162,10 +167,11 @@ services:
- ./config.json:/app/config.json:ro
command: >
${COMMON_CONFIG}
${AUTOPEERING_CONFIG}
--db.path==${DB_PATH_node5:-/app/data/database}
--protocol.snapshot.path=${SNAPSHOT_PATH_node5:-/app/data/snapshots/snapshot.bin}
--p2p.identityPrivateKey=03feb3bcd25e57f75697bb329e6e0100680431e4c45c85bc013da2aea9e9d0345e08a0c37407dc62369deebc64cb0fb3ea26127d19d141ee7fb8eaa6b92019d7
--p2p.peers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK,/dns/node-2-validator/tcp/15600/p2p/12D3KooWCropDmzpoLy8UrFg59M1oUx7k1UmQmuHrmN5RDgp6pVL,/dns/node-3-validator/tcp/15600/p2p/12D3KooWPr1mW33PGhv3oRbPQQDesN4THBB3WgnYsNzCfnQLr5QR,/dns/node-4-validator/tcp/15600/p2p/12D3KooWRxDSg2H7ThEJyn4HNkL1ixsqm6PgjCtkTG1hm7NpYG4Q,/dns/node-6/tcp/15600/p2p/12D3KooWFatFVM1wyGnMUwJrMW7YwD6j32iq5SCA9S7e386biZ73
--p2p.peerAliases=node-1-validator,node-2-validator,node-3-validator,node-4-validator,node-6
--node.alias=node-5
--inx.enabled=true
--inx.bindAddress=0.0.0.0:9029
Expand Down Expand Up @@ -196,10 +202,11 @@ services:
- ./config.json:/app/config.json:ro
command: >
${COMMON_CONFIG}
${AUTOPEERING_CONFIG}
--db.path==${DB_PATH_node6:-/app/data/database}
--protocol.snapshot.path=${SNAPSHOT_PATH_node6:-/app/data/snapshots/snapshot.bin}
--p2p.identityPrivateKey=7d1491df3ef334dee988d6cdfc4b430b996d520bd63375a01d6754f8cee979b855b200fbea8c936ea1937a27e6ad72a7c9a21c1b17c2bd3c11f1f6994d813446
--p2p.peers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK,/dns/node-2-validator/tcp/15600/p2p/12D3KooWCropDmzpoLy8UrFg59M1oUx7k1UmQmuHrmN5RDgp6pVL,/dns/node-3-validator/tcp/15600/p2p/12D3KooWPr1mW33PGhv3oRbPQQDesN4THBB3WgnYsNzCfnQLr5QR,/dns/node-4-validator/tcp/15600/p2p/12D3KooWRxDSg2H7ThEJyn4HNkL1ixsqm6PgjCtkTG1hm7NpYG4Q,/dns/node-5/tcp/15600/p2p/12D3KooWG9S868XrL1wzeUbMXDtBTAaxwuqktAzUodFFES8uoTGz
--p2p.peerAliases=node-1-validator,node-2-validator,node-3-validator,node-4-validator,node-5
--node.alias=node-6
--inx.enabled=true
--inx.bindAddress=0.0.0.0:9029
Expand Down Expand Up @@ -356,6 +363,7 @@ services:
--inx.address=node-1-validator:9029
--validator.ignoreBootstrapped=true
--validator.accountAddress=rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6
--validator.candidacyRetryInterval=${CANDIDACY_RETRY_INTERVAL:-10s}
--validator.issueCandidacyPayload=${ISSUE_CANDIDACY_PAYLOAD_V1:-true}
profiles:
- minimal
Expand All @@ -376,6 +384,7 @@ services:
--logger.level=debug
--inx.address=node-2-validator:9029
--validator.accountAddress=rms1pqm4xk8e9ny5w5rxjkvtp249tfhlwvcshyr3pc0665jvp7g3hc875k538hl
--validator.candidacyRetryInterval=${CANDIDACY_RETRY_INTERVAL:-10s}
--validator.issueCandidacyPayload=${ISSUE_CANDIDACY_PAYLOAD_V2:-true}
profiles:
- full
Expand All @@ -395,6 +404,7 @@ services:
--logger.level=debug
--inx.address=node-3-validator:9029
--validator.accountAddress=rms1pp4wuuz0y42caz48vv876qfpmffswsvg40zz8v79sy8cp0jfxm4kunflcgt
--validator.candidacyRetryInterval=${CANDIDACY_RETRY_INTERVAL:-10s}
--validator.issueCandidacyPayload=${ISSUE_CANDIDACY_PAYLOAD_V3:-true}
profiles:
- full
Expand All @@ -414,6 +424,7 @@ services:
--logger.level=debug
--inx.address=node-4-validator:9029
--validator.accountAddress=rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw
--validator.candidacyRetryInterval=${CANDIDACY_RETRY_INTERVAL:-10s}
--validator.issueCandidacyPayload=${ISSUE_CANDIDACY_PAYLOAD_V4:-true}
profiles:
- full
Expand Down
Loading

0 comments on commit 4cce1bd

Please sign in to comment.