Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/dynamic-liven…
Browse files Browse the repository at this point in the history
…ess-threshold
  • Loading branch information
jonastheis committed Sep 28, 2023
2 parents 76bb2dd + 9000c6d commit 93f30cf
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 196 deletions.
30 changes: 1 addition & 29 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/iotaledger/hive.go/runtime/contextutils"
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/hive.go/runtime/workerpool"
"github.com/iotaledger/hive.go/serializer/v2/serix"
inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
Expand Down Expand Up @@ -119,41 +118,14 @@ func (s *Server) ListenToConfirmedBlocks(_ *inx.NoParams, srv inx.INX_ListenToCo
}

func (s *Server) SubmitBlock(ctx context.Context, rawBlock *inx.RawBlock) (*inx.BlockId, error) {
version, _, err := iotago.VersionFromBytes(rawBlock.GetData())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to parse block version: %s", err.Error())
}

apiForVersion, err := deps.Protocol.APIForVersion(version)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid block version: %s", err.Error())
}

block, err := rawBlock.UnwrapBlock(apiForVersion, serix.WithValidation())
block, err := rawBlock.UnwrapBlock(deps.Protocol)
if err != nil {
return nil, err
}

return s.attachBlock(ctx, block)
}

func (s *Server) SubmitPayload(ctx context.Context, rawPayload *inx.RawPayload) (*inx.BlockId, error) {
payload, err := rawPayload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation())
if err != nil {
return nil, err
}

mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped())
defer mergedCtxCancel()

block, err := deps.BlockIssuer.CreateBlock(mergedCtx, blockIssuerAccount, blockfactory.WithPayload(payload))
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to create block: %s", err.Error())
}

return s.attachBlock(ctx, block.ProtocolBlock())
}

func (s *Server) attachBlock(ctx context.Context, block *iotago.ProtocolBlock) (*inx.BlockId, error) {
mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped())
defer mergedCtxCancel()
Expand Down
18 changes: 18 additions & 0 deletions components/inx/server_tips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package inx

import (
"context"

inx "github.com/iotaledger/inx/go"
iotago "github.com/iotaledger/iota.go/v4"
)

func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) {
references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(int(req.GetCount()))

return &inx.TipsResponse{
StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]),
WeakTips: inx.NewBlockIds(references[iotago.WeakParentType]),
ShallowLikeTips: inx.NewBlockIds(references[iotago.ShallowLikeParentType]),
}, nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132
github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd
github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I=
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs=
github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9 h1:vRGNfCcC7xwqQP0WKNQrtfBarx4y3tTnpfljmgOTMG4=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9/go.mod h1:KbmEuxbhax3fyVrxF4RjBD1/MWLFxHLNDFBnDYUzok4=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 h1:YHvgNY3/TRx84UxqizkFe7vVUxAMQB2DOuEL8wjHxpg=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132/go.mod h1:DIFr5lt73HLIyn/Lg2jtzfakwhIT0mMZjMFFji3GXeI=
github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d h1:YvE8rOrBJQu9wryUAOwEEl4mu91rpocO23qKpffKdi8=
github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQiktl3Q0B+cHbVum7WzJikOEP+buw686oSrw5Unyz8=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d h1:lhYbBhVORcS2LLNviaO/yTmom1suDskJLA1wSvvsLiU=
github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo=
github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY=
github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
14 changes: 3 additions & 11 deletions pkg/tests/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Test_TransitionAccount(t *testing.T) {

accountInput, accountOutputs, accountWallets := ts.TransactionFramework.TransitionAccount(
"Genesis:1",
testsuite.AddBlockIssuerKey(newGenesisOutputKey),
testsuite.WithAddBlockIssuerKey(newGenesisOutputKey),
testsuite.WithBlockIssuerExpirySlot(1),
)
consumedInputs, equalOutputs, equalWallets := ts.TransactionFramework.CreateBasicOutputsEqually(2, "Genesis:0")
Expand Down Expand Up @@ -127,16 +127,8 @@ func Test_TransitionAccount(t *testing.T) {
&iotago.StateControllerAddressUnlockCondition{Address: ts.TransactionFramework.DefaultAddress()},
&iotago.GovernorAddressUnlockCondition{Address: ts.TransactionFramework.DefaultAddress()},
}),
testsuite.WithBlockIssuerFeature(&iotago.BlockIssuerFeature{
BlockIssuerKeys: iotago.NewBlockIssuerKeys(newAccountBlockIssuerKey),
ExpirySlot: newAccountExpirySlot,
}),
testsuite.WithStakingFeature(&iotago.StakingFeature{
StakedAmount: 10000,
FixedCost: 421,
StartEpoch: 0,
EndEpoch: 10,
}),
testsuite.WithBlockIssuerFeature(iotago.BlockIssuerKeys{newAccountBlockIssuerKey}, newAccountExpirySlot),
testsuite.WithStakingFeature(10000, 421, 0, 10),
)

destroyedAccountInput, destructionOutputs, destroyWallets := ts.TransactionFramework.DestroyAccount("TX1:0")
Expand Down
Loading

0 comments on commit 93f30cf

Please sign in to comment.