Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Adapt to apimodel changes #535

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 16 additions & 17 deletions components/inx/server_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ 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/model"
"github.com/iotaledger/iota-core/pkg/protocol/engine/syncmanager"
iotago "github.com/iotaledger/iota.go/v4"
)

func inxNodeStatus(status *syncmanager.SyncStatus) *inx.NodeStatus {
finalizedCommitmentID := iotago.EmptyCommitmentID
var finalizedCommitment *model.Commitment
// HasPruned is false when a node just started from a snapshot and keeps data of the LastPrunedEpoch, thus still need
// to send finalized commitment.
if !status.HasPruned || status.LatestFinalizedSlot > deps.Protocol.CommittedAPI().TimeProvider().EpochEnd(status.LastPrunedEpoch) {
finalizedCommitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(status.LatestFinalizedSlot)
var err error
finalizedCommitment, err = deps.Protocol.MainEngineInstance().Storage.Commitments().Load(status.LatestFinalizedSlot)
if err != nil {
return nil
}
finalizedCommitmentID = finalizedCommitment.ID()
}

return &inx.NodeStatus{
IsHealthy: status.NodeSynced,
IsBootstrapped: status.NodeBootstrapped,
LastAcceptedBlockSlot: uint32(status.LastAcceptedBlockSlot),
LastConfirmedBlockSlot: uint32(status.LastConfirmedBlockSlot),
LatestCommitment: inxCommitment(status.LatestCommitment),
LatestFinalizedCommitmentId: inx.NewCommitmentId(finalizedCommitmentID),
PruningEpoch: uint32(status.LastPrunedEpoch),
IsHealthy: status.NodeSynced,
IsBootstrapped: status.NodeBootstrapped,
LastAcceptedBlockSlot: uint32(status.LastAcceptedBlockSlot),
LastConfirmedBlockSlot: uint32(status.LastConfirmedBlockSlot),
LatestCommitment: inxCommitment(status.LatestCommitment),
LatestFinalizedCommitment: inxCommitment(finalizedCommitment),
PruningEpoch: uint32(status.LastPrunedEpoch),
}
}

Expand Down Expand Up @@ -112,12 +112,11 @@ func (s *Server) ReadNodeConfiguration(context.Context, *inx.NoParams) (*inx.Nod

return &inx.NodeConfiguration{
BaseToken: &inx.BaseToken{
Name: deps.BaseToken.Name,
TickerSymbol: deps.BaseToken.TickerSymbol,
Unit: deps.BaseToken.Unit,
Subunit: deps.BaseToken.Subunit,
Decimals: deps.BaseToken.Decimals,
UseMetricPrefix: deps.BaseToken.UseMetricPrefix,
Name: deps.BaseToken.Name,
TickerSymbol: deps.BaseToken.TickerSymbol,
Unit: deps.BaseToken.Unit,
Subunit: deps.BaseToken.Subunit,
Decimals: deps.BaseToken.Decimals,
},
ProtocolParameters: protoParams,
}, nil
Expand Down
17 changes: 11 additions & 6 deletions components/inx/server_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func NewLedgerSpent(s *utxoledger.Spent) (*inx.LedgerSpent, error) {
return l, nil
}

func NewLedgerUpdateBatchBegin(slot iotago.SlotIndex, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
func NewLedgerUpdateBatchBegin(commitmentID iotago.CommitmentID, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
return &inx.LedgerUpdate{
Op: &inx.LedgerUpdate_BatchMarker{
BatchMarker: &inx.LedgerUpdate_Marker{
Slot: uint32(slot),
CommitmentId: inx.NewCommitmentId(commitmentID),
MarkerType: inx.LedgerUpdate_Marker_BEGIN,
CreatedCount: uint32(newOutputsCount),
ConsumedCount: uint32(newSpentsCount),
Expand All @@ -78,11 +78,11 @@ func NewLedgerUpdateBatchBegin(slot iotago.SlotIndex, newOutputsCount int, newSp
}
}

func NewLedgerUpdateBatchEnd(slot iotago.SlotIndex, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
func NewLedgerUpdateBatchEnd(commitmentID iotago.CommitmentID, newOutputsCount int, newSpentsCount int) *inx.LedgerUpdate {
return &inx.LedgerUpdate{
Op: &inx.LedgerUpdate_BatchMarker{
BatchMarker: &inx.LedgerUpdate_Marker{
Slot: uint32(slot),
CommitmentId: inx.NewCommitmentId(commitmentID),
MarkerType: inx.LedgerUpdate_Marker_END,
CreatedCount: uint32(newOutputsCount),
ConsumedCount: uint32(newSpentsCount),
Expand Down Expand Up @@ -191,8 +191,13 @@ func (s *Server) ReadUnspentOutputs(_ *inx.NoParams, srv inx.INX_ReadUnspentOutp

func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_ListenToLedgerUpdatesServer) error {
createLedgerUpdatePayloadAndSend := func(slot iotago.SlotIndex, outputs utxoledger.Outputs, spents utxoledger.Spents) error {
commitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(slot)
if err != nil {
return status.Errorf(codes.NotFound, "commitment for slot %d not found", slot)
}

// Send Begin
if err := srv.Send(NewLedgerUpdateBatchBegin(slot, len(outputs), len(spents))); err != nil {
if err := srv.Send(NewLedgerUpdateBatchBegin(commitment.ID(), len(outputs), len(spents))); err != nil {
return fmt.Errorf("send error: %w", err)
}

Expand Down Expand Up @@ -221,7 +226,7 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li
}

// Send End
if err := srv.Send(NewLedgerUpdateBatchEnd(slot, len(outputs), len(spents))); err != nil {
if err := srv.Send(NewLedgerUpdateBatchEnd(commitment.ID(), len(outputs), len(spents))); err != nil {
return fmt.Errorf("send error: %w", err)
}

Expand Down
2 changes: 0 additions & 2 deletions components/protocol/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ type BaseToken struct {
Subunit string `default:"glow" usage:"the base token subunit"`
// the base token amount of decimals
Decimals uint32 `default:"6" usage:"the base token amount of decimals"`
// the base token uses the metric prefix
UseMetricPrefix bool `default:"false" usage:"the base token uses the metric prefix"`
}

// ParametersDatabase contains the definition of configuration parameters used by the storage layer.
Expand Down
4 changes: 2 additions & 2 deletions components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func validatorByAccountID(c echo.Context) (*apimodels.ValidatorResponse, error)
}

return &apimodels.ValidatorResponse{
AccountID: accountID,
AddressBech32: accountID.ToAddress().Bech32(deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP()),
PoolStake: accountData.ValidatorStake + accountData.DelegationStake,
ValidatorStake: accountData.ValidatorStake,
StakingEpochEnd: accountData.StakeEndEpoch,
Expand Down Expand Up @@ -239,7 +239,7 @@ func selectedCommittee(c echo.Context) (*apimodels.CommitteeResponse, error) {
committee := make([]*apimodels.CommitteeMemberResponse, 0, accounts.Size())
accounts.ForEach(func(accountID iotago.AccountID, seat *account.Pool) bool {
committee = append(committee, &apimodels.CommitteeMemberResponse{
AccountID: accountID,
AddressBech32: accountID.ToAddress().Bech32(deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP()),
PoolStake: seat.PoolStake,
ValidatorStake: seat.ValidatorStake,
FixedCost: seat.FixedCost,
Expand Down
26 changes: 24 additions & 2 deletions components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/iotaledger/iota.go/v4/nodeclient/apimodels"
)

func blockByID(c echo.Context) (*model.Block, error) {
func blockByID(c echo.Context) (*iotago.Block, error) {
blockID, err := httpserver.ParseBlockIDParam(c, restapi.ParameterBlockID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse block ID %s", c.Param(restapi.ParameterBlockID))
Expand All @@ -23,7 +23,7 @@ func blockByID(c echo.Context) (*model.Block, error) {
return nil, ierrors.Wrapf(echo.ErrNotFound, "block not found: %s", blockID.ToHex())
}

return block, nil
return block.ProtocolBlock(), nil
}

func blockMetadataByBlockID(blockID iotago.BlockID) (*apimodels.BlockMetadataResponse, error) {
Expand All @@ -44,6 +44,28 @@ func blockMetadataByID(c echo.Context) (*apimodels.BlockMetadataResponse, error)
return blockMetadataByBlockID(blockID)
}

func blockWithMetadataByID(c echo.Context) (*apimodels.BlockWithMetadataResponse, error) {
blockID, err := httpserver.ParseBlockIDParam(c, restapi.ParameterBlockID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse block ID %s", c.Param(restapi.ParameterBlockID))
}

block, exists := deps.Protocol.MainEngineInstance().Block(blockID)
if !exists {
return nil, ierrors.Wrapf(echo.ErrNotFound, "block not found: %s", blockID.ToHex())
}

blockMetadata, err := blockMetadataByBlockID(blockID)
if err != nil {
return nil, err
}

return &apimodels.BlockWithMetadataResponse{
Block: block.ProtocolBlock(),
Metadata: blockMetadata,
}, nil
}

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

Expand Down
7 changes: 6 additions & 1 deletion components/restapi/core/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func getUTXOChanges(slot iotago.SlotIndex) (*apimodels.UTXOChangesResponse, erro
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to get slot diffs %d: %s", slot, err)
}

commitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(diffs.Slot)
if err != nil {
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to load commitment %d: %s", diffs.Slot, err)
}

createdOutputs := make(iotago.OutputIDs, len(diffs.Outputs))
consumedOutputs := make(iotago.OutputIDs, len(diffs.Spents))

Expand All @@ -46,7 +51,7 @@ func getUTXOChanges(slot iotago.SlotIndex) (*apimodels.UTXOChangesResponse, erro
}

return &apimodels.UTXOChangesResponse{
Slot: slot,
CommitmentID: commitment.ID(),
CreatedOutputs: createdOutputs,
ConsumedOutputs: consumedOutputs,
}, nil
Expand Down
25 changes: 20 additions & 5 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const (
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteBlockMetadata = "/blocks/:" + restapipkg.ParameterBlockID + "/metadata"

// RouteBlockWithMetadata is the route for getting a block, together with its metadata by its blockID.
// GET returns the block and metadata.
// MIMEApplicationJSON => json.
// MIMEApplicationVendorIOTASerializerV2 => bytes.
RouteBlockWithMetadata = "/blocks/:" + restapipkg.ParameterBlockID + "/full"

// 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.
Expand Down Expand Up @@ -181,12 +187,12 @@ func configure() error {
})

routeGroup.GET(RouteBlock, func(c echo.Context) error {
block, err := blockByID(c)
resp, err := blockByID(c)
if err != nil {
return err
}

return responseByHeader(c, block.ProtocolBlock())
return responseByHeader(c, resp)
})

routeGroup.GET(RouteBlockMetadata, func(c echo.Context) error {
Expand All @@ -198,6 +204,15 @@ func configure() error {
return responseByHeader(c, resp)
}, checkNodeSynced())

routeGroup.GET(RouteBlockWithMetadata, func(c echo.Context) error {
resp, err := blockWithMetadataByID(c)
if err != nil {
return err
}

return responseByHeader(c, resp)
}, checkNodeSynced())

routeGroup.POST(RouteBlocks, func(c echo.Context) error {
resp, err := sendBlock(c)
if err != nil {
Expand Down Expand Up @@ -276,7 +291,7 @@ func configure() error {
})

routeGroup.GET(RouteOutput, func(c echo.Context) error {
resp, err := getOutput(c)
resp, err := outputByID(c)
if err != nil {
return err
}
Expand All @@ -285,7 +300,7 @@ func configure() error {
})

routeGroup.GET(RouteOutputMetadata, func(c echo.Context) error {
resp, err := getOutputMetadata(c)
resp, err := outputMetadataByID(c)
if err != nil {
return err
}
Expand All @@ -294,7 +309,7 @@ func configure() error {
})

routeGroup.GET(RouteOutputWithMetadata, func(c echo.Context) error {
resp, err := getOutputWithMetadata(c)
resp, err := outputWithMetadataByID(c)
if err != nil {
return err
}
Expand Down
11 changes: 5 additions & 6 deletions components/restapi/core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ func info() *apimodels.InfoResponse {
},
ProtocolParameters: protocolParameters(),
BaseToken: &apimodels.InfoResBaseToken{
Name: deps.BaseToken.Name,
TickerSymbol: deps.BaseToken.TickerSymbol,
Unit: deps.BaseToken.Unit,
Subunit: deps.BaseToken.Subunit,
Decimals: deps.BaseToken.Decimals,
UseMetricPrefix: deps.BaseToken.UseMetricPrefix,
Name: deps.BaseToken.Name,
TickerSymbol: deps.BaseToken.TickerSymbol,
Unit: deps.BaseToken.Unit,
Subunit: deps.BaseToken.Subunit,
Decimals: deps.BaseToken.Decimals,
},
Features: features,
}
Expand Down
6 changes: 3 additions & 3 deletions components/restapi/core/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/iotaledger/iota.go/v4/nodeclient/apimodels"
)

func getOutput(c echo.Context) (*apimodels.OutputResponse, error) {
func outputByID(c echo.Context) (*apimodels.OutputResponse, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID %s", c.Param(restapipkg.ParameterOutputID))
Expand All @@ -27,7 +27,7 @@ func getOutput(c echo.Context) (*apimodels.OutputResponse, error) {
}, nil
}

func getOutputMetadata(c echo.Context) (*apimodels.OutputMetadata, error) {
func outputMetadataByID(c echo.Context) (*apimodels.OutputMetadata, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID %s", c.Param(restapipkg.ParameterOutputID))
Expand All @@ -45,7 +45,7 @@ func getOutputMetadata(c echo.Context) (*apimodels.OutputMetadata, error) {
return newOutputMetadataResponse(output)
}

func getOutputWithMetadata(c echo.Context) (*apimodels.OutputWithMetadataResponse, error) {
func outputWithMetadataByID(c echo.Context) (*apimodels.OutputWithMetadataResponse, error) {
outputID, err := httpserver.ParseOutputIDParam(c, restapipkg.ParameterOutputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to parse output ID %s", c.Param(restapipkg.ParameterOutputID))
Expand Down
3 changes: 1 addition & 2 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@
"tickerSymbol": "SMR",
"unit": "SMR",
"subunit": "glow",
"decimals": 6,
"useMetricPrefix": false
"decimals": 6
}
},
"dashboard": {
Expand Down
18 changes: 8 additions & 10 deletions documentation/docs/references/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,13 @@ Example:

### <a id="protocol_basetoken"></a> BaseToken

| Name | Description | Type | Default value |
| --------------- | ------------------------------------- | ------- | ------------- |
| name | The base token name | string | "Shimmer" |
| tickerSymbol | The base token ticker symbol | string | "SMR" |
| unit | The base token unit | string | "SMR" |
| subunit | The base token subunit | string | "glow" |
| decimals | The base token amount of decimals | uint | 6 |
| useMetricPrefix | The base token uses the metric prefix | boolean | false |
| Name | Description | Type | Default value |
| ------------ | --------------------------------- | ------ | ------------- |
| name | The base token name | string | "Shimmer" |
| tickerSymbol | The base token ticker symbol | string | "SMR" |
| unit | The base token unit | string | "SMR" |
| subunit | The base token subunit | string | "glow" |
| decimals | The base token amount of decimals | uint | 6 |

Example:

Expand All @@ -368,8 +367,7 @@ Example:
"tickerSymbol": "SMR",
"unit": "SMR",
"subunit": "glow",
"decimals": 6,
"useMetricPrefix": false
"decimals": 6
}
}
}
Expand Down
Loading
Loading