From 093ebfa52d0087dfe1855be6d0b64ba2a9961e8a Mon Sep 17 00:00:00 2001 From: muXxer Date: Mon, 20 Nov 2023 11:49:04 +0100 Subject: [PATCH] Send commitment via inx --- components/inx/server_node.go | 22 +++++++++++----------- components/inx/server_utxo.go | 17 +++++++++++------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/components/inx/server_node.go b/components/inx/server_node.go index c17c46062..959e412ac 100644 --- a/components/inx/server_node.go +++ b/components/inx/server_node.go @@ -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), } } diff --git a/components/inx/server_utxo.go b/components/inx/server_utxo.go index a5fb5dfc4..4cab44670 100644 --- a/components/inx/server_utxo.go +++ b/components/inx/server_utxo.go @@ -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), @@ -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), @@ -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) } @@ -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) }