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

Extract block issuer from node in tests and components #400

Merged
merged 17 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
2 changes: 0 additions & 2 deletions components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/components/profiling"
"github.com/iotaledger/hive.go/app/components/shutdown"
"github.com/iotaledger/iota-core/components/blockissuer"
"github.com/iotaledger/iota-core/components/dashboard"
dashboardmetrics "github.com/iotaledger/iota-core/components/dashboard_metrics"
"github.com/iotaledger/iota-core/components/debugapi"
Expand Down Expand Up @@ -39,7 +38,6 @@ func App() *app.App {
debugapi.Component,
metricstracker.Component,
protocol.Component,
blockissuer.Component,
validator.Component,
dashboardmetrics.Component,
dashboard.Component,
Expand Down
63 changes: 0 additions & 63 deletions components/blockissuer/component.go

This file was deleted.

32 changes: 0 additions & 32 deletions components/blockissuer/params.go

This file was deleted.

20 changes: 6 additions & 14 deletions components/inx/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/iota-core/components/protocol"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/blockhandler"
"github.com/iotaledger/iota-core/pkg/daemon"
protocolpkg "github.com/iotaledger/iota-core/pkg/protocol"
restapipkg "github.com/iotaledger/iota-core/pkg/restapi"
Expand All @@ -22,22 +22,20 @@ func init() {
IsEnabled: func(c *dig.Container) bool {
return ParamsINX.Enabled
},
Provide: provide,
Configure: configure,
Run: run,
Provide: provide,
Run: run,
}
}

var (
Component *app.Component
deps dependencies
blockIssuerAccount blockfactory.Account
Component *app.Component
deps dependencies
)

type dependencies struct {
dig.In
Protocol *protocolpkg.Protocol
BlockIssuer *blockfactory.BlockIssuer
BlockHandler *blockhandler.BlockHandler
Echo *echo.Echo `optional:"true"`
RestRouteManager *restapipkg.RestRouteManager
INXServer *Server
Expand All @@ -54,12 +52,6 @@ func provide(c *dig.Container) error {
return nil
}

func configure() error {
blockIssuerAccount = blockfactory.AccountFromParams(ParamsINX.BlockIssuerAccount, ParamsINX.BlockIssuerPrivateKey)

return nil
}

func run() error {
if err := Component.Daemon().BackgroundWorker("INX", func(ctx context.Context) {
Component.LogInfo("Starting INX ... done")
Expand Down
4 changes: 0 additions & 4 deletions components/inx/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ type ParametersINX struct {
Enabled bool `default:"false" usage:"whether the INX plugin is enabled"`
// the bind address on which the INX can be accessed from
BindAddress string `default:"localhost:9029" usage:"the bind address on which the INX can be accessed from"`
// BlockIssuerAccount the accountID of the account that will issue the blocks.
BlockIssuerAccount string `default:"" usage:"the accountID of the account that will issue the blocks"`
// BlockIssuerPrivateKey the private key of the account that will issue the blocks.
BlockIssuerPrivateKey string `default:"" usage:"the private key of the account that will issue the blocks"`
}

var ParamsINX = &ParametersINX{}
Expand Down
8 changes: 4 additions & 4 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/hive.go/runtime/workerpool"
inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/blockhandler"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
iotago "github.com/iotaledger/iota.go/v4"
)
Expand Down Expand Up @@ -130,13 +130,13 @@ func (s *Server) attachBlock(ctx context.Context, block *iotago.ProtocolBlock) (
mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped())
defer mergedCtxCancel()

blockID, err := deps.BlockIssuer.AttachBlock(mergedCtx, block, blockIssuerAccount)
blockID, err := deps.BlockHandler.AttachBlock(mergedCtx, block)
if err != nil {
switch {
case ierrors.Is(err, blockfactory.ErrBlockAttacherInvalidBlock):
case ierrors.Is(err, blockhandler.ErrBlockAttacherInvalidBlock):
return nil, status.Errorf(codes.InvalidArgument, "failed to attach block: %s", err.Error())

case ierrors.Is(err, blockfactory.ErrBlockAttacherAttachingNotPossible):
case ierrors.Is(err, blockhandler.ErrBlockAttacherAttachingNotPossible):
return nil, status.Errorf(codes.Internal, "failed to attach block: %s", err.Error())

default:
Expand Down
8 changes: 4 additions & 4 deletions components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/inx-app/pkg/httpserver"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/blockhandler"
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/restapi"
iotago "github.com/iotaledger/iota.go/v4"
Expand Down Expand Up @@ -110,13 +110,13 @@ func sendBlock(c echo.Context) (*apimodels.BlockCreatedResponse, error) {
return nil, echo.ErrUnsupportedMediaType
}

blockID, err := deps.BlockIssuer.AttachBlock(c.Request().Context(), iotaBlock, blockIssuerAccount)
blockID, err := deps.BlockHandler.AttachBlock(c.Request().Context(), iotaBlock)
if err != nil {
switch {
case ierrors.Is(err, blockfactory.ErrBlockAttacherInvalidBlock):
case ierrors.Is(err, blockhandler.ErrBlockAttacherInvalidBlock):
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "failed to attach block: %w", err)

case ierrors.Is(err, blockfactory.ErrBlockAttacherAttachingNotPossible):
case ierrors.Is(err, blockhandler.ErrBlockAttacherAttachingNotPossible):
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to attach block: %w", err)

default:
Expand Down
31 changes: 5 additions & 26 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/iotaledger/iota-core/components/metricstracker"
"github.com/iotaledger/iota-core/components/protocol"
"github.com/iotaledger/iota-core/components/restapi"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/blockhandler"
protocolpkg "github.com/iotaledger/iota-core/pkg/protocol"
restapipkg "github.com/iotaledger/iota-core/pkg/restapi"
)
Expand All @@ -39,10 +39,9 @@ const (
// GET returns block metadata.
RouteBlockMetadata = "/blocks/:" + restapipkg.ParameterBlockID + "/metadata"

// RouteBlocks is the route for creating new blocks.
// RouteBlocks is the route for sending new blocks.
// POST creates a single new block and returns the new block ID.
// The block is parsed based on the given type in the request "Content-Type" header.
// By providing only the protocolVersion and payload transaction user can POST a transaction.
// MIMEApplicationJSON => json.
// MIMEVendorIOTASerializer => bytes.
RouteBlocks = "/blocks"
cyberphysic4l marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -134,8 +133,7 @@ var (
Component *app.Component
deps dependencies

blockIssuerAccount blockfactory.Account
features = []string{}
features = []string{}
)

type dependencies struct {
Expand All @@ -144,7 +142,7 @@ type dependencies struct {
AppInfo *app.Info
RestRouteManager *restapipkg.RestRouteManager
Protocol *protocolpkg.Protocol
BlockIssuer *blockfactory.BlockIssuer `optional:"true"`
BlockHandler *blockhandler.BlockHandler
MetricsTracker *metricstracker.MetricsTracker
BaseToken *protocol.BaseToken
}
Expand All @@ -157,12 +155,6 @@ func configure() error {

routeGroup := deps.RestRouteManager.AddRoute("core/v3")

if restapi.ParamsRestAPI.AllowIncompleteBlock {
AddFeature("allowIncompleteBlock")
}

blockIssuerAccount = blockfactory.AccountFromParams(restapi.ParamsRestAPI.BlockIssuerAccount, restapi.ParamsRestAPI.BlockIssuerPrivateKey)

routeGroup.GET(RouteInfo, func(c echo.Context) error {
resp := info()

Expand Down Expand Up @@ -195,7 +187,7 @@ func configure() error {
c.Response().Header().Set(echo.HeaderLocation, resp.BlockID.ToHex())

return httpserver.JSONResponse(c, http.StatusCreated, resp)
}, checkNodeSynced(), checkUpcomingUnsupportedProtocolVersion())
}, checkNodeSynced())

routeGroup.GET(RouteBlockIssuance, func(c echo.Context) error {
resp, err := blockIssuance(c)
Expand Down Expand Up @@ -360,19 +352,6 @@ func checkNodeSynced() echo.MiddlewareFunc {
}
}

func checkUpcomingUnsupportedProtocolVersion() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// todo update with protocol upgrades support
// if !deps.ProtocolManager.NextPendingSupported() {
// return ierrors.Wrap(echo.ErrServiceUnavailable, "node does not support the upcoming protocol upgrade")
// }

return next(c)
}
}
}

func responseByHeader(c echo.Context, obj any) error {
mimeType, err := httpserver.GetAcceptHeaderContentType(c, httpserver.MIMEApplicationVendorIOTASerializerV2, echo.MIMEApplicationJSON)
if err != nil && err != httpserver.ErrNotAcceptable {
Expand Down
8 changes: 0 additions & 8 deletions components/restapi/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ type ParametersRestAPI struct {
ProtectedRoutes []string `usage:"the HTTP REST routes which need to be called with authorization. Wildcards using * are allowed"`
// whether the debug logging for requests should be enabled
DebugRequestLoggerEnabled bool `default:"false" usage:"whether the debug logging for requests should be enabled"`
// AllowIncompleteBlock defines whether the node allows to fill in incomplete block and issue it for user.
AllowIncompleteBlock bool `default:"false" usage:"whether the node allows to fill in incomplete block and issue it for user"`
// MaxPageSize defines the maximum number of results per page.
MaxPageSize uint32 `default:"100" usage:"the maximum number of results per page"`
// RequestsMemoryCacheGranularity defines per how many slots a cache is created for big API requests.
Expand All @@ -36,12 +34,6 @@ type ParametersRestAPI struct {
// the maximum number of results that may be returned by an endpoint
MaxResults int `default:"1000" usage:"the maximum number of results that may be returned by an endpoint"`
}

// BlockIssuerAccount the accountID of the account that will issue the blocks.
BlockIssuerAccount string `default:"" usage:"the accountID of the account that will issue the blocks"`

// BlockIssuerPrivateKey the private key of the account that will issue the blocks.
BlockIssuerPrivateKey string `default:"" usage:"the private key of the account that will issue the blocks"`
}

var ParamsRestAPI = &ParametersRestAPI{
Expand Down
13 changes: 6 additions & 7 deletions components/validator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/hive.go/runtime/timed"
"github.com/iotaledger/iota-core/components/blockissuer"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/blockhandler"
"github.com/iotaledger/iota-core/pkg/daemon"
"github.com/iotaledger/iota-core/pkg/protocol"
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization"
Expand All @@ -25,7 +24,7 @@ func init() {
Params: params,
Run: run,
IsEnabled: func(_ *dig.Container) bool {
return ParamsValidator.Enabled && blockissuer.ParamsBlockIssuer.Enabled
return ParamsValidator.Enabled
},
}
}
Expand All @@ -36,18 +35,18 @@ var (

isValidator atomic.Bool
executor *timed.TaskExecutor[iotago.AccountID]
validatorAccount blockfactory.Account
validatorAccount blockhandler.Account
)

type dependencies struct {
dig.In

Protocol *protocol.Protocol
BlockIssuer *blockfactory.BlockIssuer
Protocol *protocol.Protocol
BlockHandler *blockhandler.BlockHandler
}

func run() error {
validatorAccount = blockfactory.AccountFromParams(ParamsValidator.Account, ParamsValidator.PrivateKey)
validatorAccount = blockhandler.AccountFromParams(ParamsValidator.Account, ParamsValidator.PrivateKey)

executor = timed.NewTaskExecutor[iotago.AccountID](1)

Expand Down
Loading
Loading