Skip to content

Commit

Permalink
Merge branch 'develop' into fix/conflicting-tx-reason
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Nov 21, 2023
2 parents f63865c + 2dc7db9 commit 9e667b2
Show file tree
Hide file tree
Showing 59 changed files with 955 additions and 643 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/feature-network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- uses: actions/setup-go@v4
with:
go-version-file: 'tools/genesis-snapshot/go.mod'
cache: false

- name: Print Go version
run: go version

- name: Generate genesis snapshot
working-directory: tools/genesis-snapshot
run: go run -tags=rocksdb . --config feature --seed 7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih --filename genesis-snapshot.bin

- name: Upload snapshot
id: upload-snapshot
run: |
SNAPSHOT_URL=$(curl -T ./tools/genesis-snapshot/genesis-snapshot.bin https://transfer.sh)
echo "Snapshot URL: $SNAPSHOT_URL"
echo "snapshot_url=$SNAPSHOT_URL" >> $GITHUB_OUTPUT
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
Expand All @@ -70,7 +89,7 @@ jobs:
- name: Ansible deploy
env:
CUSTOM_SNAPSHOT_URL: '${{ github.event.inputs.snapshotUrl }}'
DEFAULT_SNAPSHOT_URL: 'https://0x0.st/HywH.bin'
DEFAULT_SNAPSHOT_URL: '${{ steps.upload-snapshot.outputs.snapshot_url }}'
NETWORK_ENVIRONMENT: '${{ secrets.NETWORK_ENVIRONMENT }}'
IOTA_CORE_DOCKER_IMAGE_REPO: 'iotaledger/iota-core'
IOTA_CORE_DOCKER_IMAGE_TAG: 'feature'
Expand Down
20 changes: 20 additions & 0 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func (s *Server) ListenToBlocks(_ *inx.NoParams, srv inx.INX_ListenToBlocksServe

unhook := deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(block *blocks.Block) {
payload := inx.NewBlockWithBytes(block.ID(), block.ModelBlock().Data())

if ctx.Err() != nil {
// context is done, so we don't need to send the payload
return
}

if err := srv.Send(payload); err != nil {
Component.LogErrorf("send error: %v", err)
cancel()
Expand Down Expand Up @@ -74,6 +80,13 @@ func (s *Server) ListenToAcceptedBlocks(_ *inx.NoParams, srv inx.INX_ListenToAcc
if err != nil {
Component.LogErrorf("get block metadata error: %v", err)
cancel()

return
}

if ctx.Err() != nil {
// context is done, so we don't need to send the payload
return
}

if err := srv.Send(payload); err != nil {
Expand Down Expand Up @@ -104,6 +117,13 @@ func (s *Server) ListenToConfirmedBlocks(_ *inx.NoParams, srv inx.INX_ListenToCo
if err != nil {
Component.LogErrorf("get block metadata error: %v", err)
cancel()

return
}

if ctx.Err() != nil {
// context is done, so we don't need to send the payload
return
}

if err := srv.Send(payload); err != nil {
Expand Down
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
42 changes: 30 additions & 12 deletions components/inx/server_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/iotaledger/hive.go/runtime/workerpool"
inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota-core/pkg/protocol/engine/mempool"
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization"
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
iotago "github.com/iotaledger/iota.go/v4"
)
Expand All @@ -29,7 +30,7 @@ func NewLedgerOutput(o *utxoledger.Output) (*inx.LedgerOutput, error) {
}

includedSlot := o.SlotBooked()
if includedSlot <= latestCommitment.Slot() {
if includedSlot > 0 && includedSlot <= latestCommitment.Slot() {
includedCommitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(includedSlot)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to load commitment with slot: %d", includedSlot)
Expand All @@ -54,7 +55,7 @@ func NewLedgerSpent(s *utxoledger.Spent) (*inx.LedgerSpent, error) {

latestCommitment := deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment()
spentSlot := s.SlotSpent()
if spentSlot <= latestCommitment.Slot() {
if spentSlot > 0 && spentSlot <= latestCommitment.Slot() {
spentCommitment, err := deps.Protocol.MainEngineInstance().Storage.Commitments().Load(spentSlot)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to load commitment with slot: %d", spentSlot)
Expand All @@ -65,11 +66,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 +79,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 +192,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 +227,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 Expand Up @@ -317,8 +323,8 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li

wp := workerpool.New("ListenToLedgerUpdates", workerpool.WithWorkerCount(workerCount)).Start()

unhook := deps.Protocol.Events.Engine.Ledger.StateDiffApplied.Hook(func(slot iotago.SlotIndex, newOutputs utxoledger.Outputs, newSpents utxoledger.Spents) {
done, err := handleRangedSend2(slot, newOutputs, newSpents, stream, catchUpFunc, sendFunc)
unhook := deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(scd *notarization.SlotCommittedDetails) {
done, err := handleRangedSend2(scd.Commitment.Slot(), scd.OutputsCreated, scd.OutputsConsumed, stream, catchUpFunc, sendFunc)
switch {
case err != nil:
innerErr = err
Expand Down Expand Up @@ -353,7 +359,8 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste
if err := transactionMetadata.Inputs().ForEach(func(stateMetadata mempool.StateMetadata) error {
spentOutput, ok := stateMetadata.State().(*utxoledger.Output)
if !ok {
return ierrors.Errorf("unexpected state metadata type: %T", stateMetadata.State())
// not an Output, so we don't need to send it (could be MockedState, Commitment, BlockIssuanceCreditInput, RewardInput, etc.)
return nil
}

inxSpent, err := NewLedgerSpent(utxoledger.NewSpent(spentOutput, transactionMetadata.ID(), slot))
Expand All @@ -366,13 +373,16 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste
}); err != nil {
Component.LogErrorf("error creating payload: %v", err)
cancel()

return
}

var created []*inx.LedgerOutput
if err := transactionMetadata.Outputs().ForEach(func(stateMetadata mempool.StateMetadata) error {
output, ok := stateMetadata.State().(*utxoledger.Output)
if !ok {
return ierrors.Errorf("unexpected state metadata type: %T", stateMetadata.State())
// not an Output, so we don't need to send it (could be MockedState, Commitment, BlockIssuanceCreditInput, RewardInput, etc.)
return nil
}

inxOutput, err := NewLedgerOutput(output)
Expand All @@ -385,6 +395,8 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste
}); err != nil {
Component.LogErrorf("error creating payload: %v", err)
cancel()

return
}

payload := &inx.AcceptedTransaction{
Expand All @@ -393,6 +405,12 @@ func (s *Server) ListenToAcceptedTransactions(_ *inx.NoParams, srv inx.INX_Liste
Consumed: consumed,
Created: created,
}

if ctx.Err() != nil {
// context is done, so we don't need to send the payload
return
}

if err := srv.Send(payload); err != nil {
Component.LogErrorf("send error: %v", err)
cancel()
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
Loading

0 comments on commit 9e667b2

Please sign in to comment.