Skip to content

Commit

Permalink
rename max parents
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberphysic4l committed Nov 2, 2023
1 parent c6d2323 commit e81779e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func blockMetadataByID(c echo.Context) (*apimodels.BlockMetadataResponse, error)
}

func blockIssuanceBySlot(slotIndex iotago.SlotIndex) (*apimodels.IssuanceBlockHeaderResponse, error) {
references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(iotago.BlockMaxParents)
references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(iotago.BasicBlockMaxParents)

var slotCommitment *model.Commitment
var err error
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e
github.com/labstack/echo/v4 v4.11.2
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.32.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5 h1:17JDz
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5/go.mod h1:LsJvoBUVVnY7tkwwByCVtAwmp5bFXdyJNGU/+KVQJVM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac h1:c7R33+TQGMYP6pvLUQQaqpdDFl+GZbhAcfGMI0285fo=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac/go.mod h1:qPuMUvCTaghsnYRDnRoRuztTyEKFlmi2S7gb44rH7WM=
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967 h1:qiBW4TiRdzVJshLu7RoWn9ur64SFLCOQ0oFtQWtz4bk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e h1:ZYRC1MHn/ghsqtjIpYGTxLQrh5n5eUmC0/YWnJiTRhk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/testframework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (t *TestFramework) GeneratePrunableData(epoch iotago.EpochIndex, size int64
var createdBytes int64
for createdBytes < size {
block := tpkg.RandBlock(&iotago.BasicBlockBody{
StrongParents: tpkg.SortedRandBlockIDs(1 + rand.Intn(iotago.BlockMaxParents)),
StrongParents: tpkg.SortedRandBlockIDs(1 + rand.Intn(iotago.BasicBlockMaxParents)),
Payload: &iotago.TaggedData{Data: make([]byte, 8192)},
MaxBurnedMana: 1000,
}, apiForEpoch, 0)
Expand Down
45 changes: 30 additions & 15 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, i
}

if blockParams.BlockHeader.References == nil {
// TODO: change this to get references for validator block
references, err := i.getReferences(ctx, nil, node, blockParams.BlockHeader.ParentsCount)
references, err := i.getReferencesValidationBlock(ctx, node, blockParams.BlockHeader.ParentsCount)
require.NoError(i.Testing, err)

blockParams.BlockHeader.References = references
Expand Down Expand Up @@ -226,7 +225,7 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, node *
}

if blockParams.BlockHeader.References == nil {
references, err := i.getReferences(ctx, blockParams.Payload, node, blockParams.BlockHeader.ParentsCount)
references, err := i.getReferencesBasicBlock(ctx, node, blockParams.BlockHeader.ParentsCount)
require.NoError(i.Testing, err)
blockParams.BlockHeader.References = references
}
Expand Down Expand Up @@ -388,31 +387,38 @@ func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Block,
resign = true
}

switch innerBlock := iotaBlock.Body.(type) {
switch blockBody := iotaBlock.Body.(type) {
case *iotago.BasicBlockBody:
switch payload := innerBlock.Payload.(type) {
switch payload := blockBody.Payload.(type) {
case *iotago.SignedTransaction:
if payload.Transaction.NetworkID != protoParams.NetworkID() {
return iotago.EmptyBlockID, ierrors.Wrapf(ErrBlockAttacherInvalidBlock, "invalid payload, error: wrong networkID: %d", payload.Transaction.NetworkID)
}
}

if len(iotaBlock.Parents()) == 0 {
references, referencesErr := i.getReferences(ctx, innerBlock.Payload, node)
references, referencesErr := i.getReferencesBasicBlock(ctx, node)
if referencesErr != nil {
return iotago.EmptyBlockID, ierrors.Wrapf(ErrBlockAttacherAttachingNotPossible, "tipselection failed, error: %w", referencesErr)
}

innerBlock.StrongParents = references[iotago.StrongParentType]
innerBlock.WeakParents = references[iotago.WeakParentType]
innerBlock.ShallowLikeParents = references[iotago.ShallowLikeParentType]
blockBody.StrongParents = references[iotago.StrongParentType]
blockBody.WeakParents = references[iotago.WeakParentType]
blockBody.ShallowLikeParents = references[iotago.ShallowLikeParentType]
resign = true
}

case *iotago.ValidationBlockBody:
//nolint:revive,staticcheck //temporarily disable
if len(iotaBlock.Parents()) == 0 {
// TODO: implement tipselection for validator blocks
references, referencesErr := i.getReferencesValidationBlock(ctx, node)
if referencesErr != nil {
return iotago.EmptyBlockID, ierrors.Wrapf(ErrBlockAttacherAttachingNotPossible, "tipselection failed, error: %w", referencesErr)
}

blockBody.StrongParents = references[iotago.StrongParentType]
blockBody.WeakParents = references[iotago.WeakParentType]
blockBody.ShallowLikeParents = references[iotago.ShallowLikeParentType]
resign = true
}
}

Expand Down Expand Up @@ -544,13 +550,22 @@ func (i *BlockIssuer) getAddressableCommitment(currentAPI iotago.API, blockIssui
return commitment, nil
}

func (i *BlockIssuer) getReferences(ctx context.Context, p iotago.Payload, node *Node, strongParentsCountOpt ...int) (model.ParentReferences, error) {
strongParentsCount := iotago.BlockMaxParents
func (i *BlockIssuer) getReferencesBasicBlock(ctx context.Context, node *Node, strongParentsCountOpt ...int) (model.ParentReferences, error) {
strongParentsCount := iotago.BasicBlockMaxParents
if len(strongParentsCountOpt) > 0 && strongParentsCountOpt[0] > 0 {
strongParentsCount = strongParentsCountOpt[0]
}

return i.getReferencesWithRetry(ctx, strongParentsCount, node)
}

func (i *BlockIssuer) getReferencesValidationBlock(ctx context.Context, node *Node, strongParentsCountOpt ...int) (model.ParentReferences, error) {
strongParentsCount := iotago.ValidationBlockMaxParents
if len(strongParentsCountOpt) > 0 && strongParentsCountOpt[0] > 0 {
strongParentsCount = strongParentsCountOpt[0]
}

return i.getReferencesWithRetry(ctx, p, strongParentsCount, node)
return i.getReferencesWithRetry(ctx, strongParentsCount, node)
}

func (i *BlockIssuer) validateReferences(issuingTime time.Time, slotCommitmentIndex iotago.SlotIndex, references model.ParentReferences, node *Node) error {
Expand Down Expand Up @@ -594,7 +609,7 @@ func (i *BlockIssuer) CopyIdentityFromBlockIssuer(otherBlockIssuer *BlockIssuer)

// getReferencesWithRetry tries to get references for the given payload. If it fails, it will retry at regular intervals until
// the timeout is reached.
func (i *BlockIssuer) getReferencesWithRetry(ctx context.Context, _ iotago.Payload, parentsCount int, node *Node) (references model.ParentReferences, err error) {
func (i *BlockIssuer) getReferencesWithRetry(ctx context.Context, parentsCount int, node *Node) (references model.ParentReferences, err error) {
timeout := time.NewTimer(i.optsTipSelectionTimeout)
interval := time.NewTicker(i.optsTipSelectionRetryInterval)
defer timeutil.CleanupTimer(timeout)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testsuite/testsuite_issue_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (t *TestSuite) IssueBlockRowInSlot(prefix string, slot iotago.SlotIndex, ro
}
tx := t.DefaultWallet().CreateBasicOutputsEquallyFromInputs(txName, 1, inputName)

issuingOptionsCopy[node.Name] = t.limitParentsCountInBlockOptions(issuingOptionsCopy[node.Name], iotago.BlockMaxParents)
issuingOptionsCopy[node.Name] = t.limitParentsCountInBlockOptions(issuingOptionsCopy[node.Name], iotago.BasicBlockMaxParents)

blockHeaderOptions := append(issuingOptionsCopy[node.Name], mock.WithIssuingTime(issuingTime))
t.assertParentsCommitmentExistFromBlockOptions(blockHeaderOptions, node)
Expand Down
2 changes: 1 addition & 1 deletion tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42 // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e // indirect
github.com/ipfs/boxo v0.13.1 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5 h1:17JDz
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5/go.mod h1:LsJvoBUVVnY7tkwwByCVtAwmp5bFXdyJNGU/+KVQJVM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac h1:c7R33+TQGMYP6pvLUQQaqpdDFl+GZbhAcfGMI0285fo=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac/go.mod h1:qPuMUvCTaghsnYRDnRoRuztTyEKFlmi2S7gb44rH7WM=
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967 h1:qiBW4TiRdzVJshLu7RoWn9ur64SFLCOQ0oFtQWtz4bk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e h1:ZYRC1MHn/ghsqtjIpYGTxLQrh5n5eUmC0/YWnJiTRhk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/iotaledger/hive.go/lo v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/hive.go/runtime v0.0.0-20231027195901-620bd7470e42
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e
github.com/mr-tron/base58 v1.2.0
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.14.0
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis-snapshot/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231027195901-620bd74
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231027195901-620bd7470e42/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42 h1:OlDhgvJ48bZxcvTeebJ1b96xtNnJAddejd2Q4rlH1mU=
github.com/iotaledger/hive.go/stringify v0.0.0-20231027195901-620bd7470e42/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967 h1:qiBW4TiRdzVJshLu7RoWn9ur64SFLCOQ0oFtQWtz4bk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231031113109-5d7d59311967/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e h1:ZYRC1MHn/ghsqtjIpYGTxLQrh5n5eUmC0/YWnJiTRhk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
Expand Down

0 comments on commit e81779e

Please sign in to comment.