Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/simplify-seri…
Browse files Browse the repository at this point in the history
…alization
  • Loading branch information
jonastheis committed Nov 6, 2023
2 parents 7f5bd3d + c641e82 commit 9e59adb
Show file tree
Hide file tree
Showing 65 changed files with 841 additions and 973 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

build:
name: Import Check
runs-on: ubuntu-latest
runs-on: self-hosted
steps:

- name: Checkout repository
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/docker-network-health.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Run Docker Network and Check Health

on:
workflow_dispatch:
pull_request:
paths-ignore:
- 'documentation/**'
- 'scripts/**'
- 'tools/**'

concurrency:
group: run-and-check-group
cancel-in-progress: false

jobs:
run-and-check:
runs-on: self-hosted

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run network, wait and check health
run: |
set -x
# Run network
cd ./tools/docker-network
timeout 10m ./run.sh 0 0 &
RUN_PID=$!
# Wait for node-4 to be created before querying it
timeout 10m bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' &
# Wait for any of the two processes to exit
wait -n || exit 1
# Additional 10 seconds wait to allow the API to come up
sleep 10
# Health check
SUCCESS=false
while true; do
OUTPUT=$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost:8080/health)
if [[ $OUTPUT -eq 200 ]]; then
SUCCESS=true
kill -s SIGINT $RUN_PID
break
# curl will return a connection refused when the network is tear down from the timeout.
elif [[ $OUTPUT -eq 000 ]]; then
echo "Connection refused. Failing the action."
break
fi
sleep 5
done
if [[ ! $SUCCESS ]]; then
echo "Health check never returned 200. Failing the action."
exit 1
fi
- name: Cleanup
run: |
cd ./tools/docker-network
docker compose kill
docker compose down -v
2 changes: 1 addition & 1 deletion .github/workflows/feature-network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Ansible deploy
env:
CUSTOM_SNAPSHOT_URL: '${{ github.event.inputs.snapshotUrl }}'
DEFAULT_SNAPSHOT_URL: 'https://0x0.st/HJXh.bin'
DEFAULT_SNAPSHOT_URL: 'https://0x0.st/HywH.bin'
NETWORK_ENVIRONMENT: '${{ secrets.NETWORK_ENVIRONMENT }}'
IOTA_CORE_DOCKER_IMAGE_REPO: 'iotaledger/iota-core'
IOTA_CORE_DOCKER_IMAGE_TAG: 'feature'
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ iota-core
# IDE related files
.vscode/
.idea/
go.work
go.work.sum
go.work*

# dist packages
dist/
Expand Down
2 changes: 0 additions & 2 deletions components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/iotaledger/iota-core/components/protocol"
"github.com/iotaledger/iota-core/components/restapi"
coreapi "github.com/iotaledger/iota-core/components/restapi/core"
"github.com/iotaledger/iota-core/components/validator"
"github.com/iotaledger/iota-core/pkg/toolset"
)

Expand Down Expand Up @@ -48,7 +47,6 @@ Command line flags:
debugapi.Component,
metricstracker.Component,
protocol.Component,
validator.Component,
dashboardmetrics.Component,
dashboard.Component,
metrics.Component,
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func currentNodeStatus() *nodestatus {

status.TangleTime = tangleTime{
Synced: syncStatus.NodeSynced,
Bootstrapped: deps.Protocol.MainEngineInstance().SyncManager.IsBootstrapped(),
Bootstrapped: syncStatus.NodeBootstrapped,
AcceptedBlockSlot: int64(syncStatus.LastAcceptedBlockSlot),
ConfirmedBlockSlot: int64(syncStatus.LastConfirmedBlockSlot),
CommittedSlot: int64(syncStatus.LatestCommitment.Slot()),
Expand Down
7 changes: 6 additions & 1 deletion components/debugapi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ func validatorsSummary() (*ValidatorsSummaryResponse, error) {
}

var validatorSeats []*Validator
latestCommittee.Accounts().ForEach(func(id iotago.AccountID, pool *account.Pool) bool {
accounts, err := latestCommittee.Accounts()
if err != nil {
return nil, ierrors.Wrapf(err, "failed to get accounts from committee for slot %d", latestSlotIndex)
}

accounts.ForEach(func(id iotago.AccountID, pool *account.Pool) bool {
validatorSeats = append(validatorSeats, &Validator{
AccountID: id,
SeatIndex: uint8(lo.Return1(latestCommittee.GetSeat(id))),
Expand Down
53 changes: 53 additions & 0 deletions components/inx/server_accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package inx

import (
"context"

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

func (s *Server) ReadIsValidatorAccount(_ context.Context, accountInfoRequest *inx.AccountInfoRequest) (*inx.BoolResponse, error) {
slot := iotago.SlotIndex(accountInfoRequest.GetAccountSlot())
accountID, _, err := iotago.AccountIDFromBytes(accountInfoRequest.AccountId)
if err != nil {
return nil, ierrors.Wrap(err, "error when parsing account id")
}

account, exists, err := deps.Protocol.MainEngineInstance().Ledger.Account(accountID, slot)
if err != nil {
return nil, ierrors.Wrapf(err, "error when retrieving account data for %s", accountID)
}

return inx.WrapBoolResponse(exists && account.StakeEndEpoch <= deps.Protocol.APIForSlot(slot).TimeProvider().EpochFromSlot(slot)), nil
}

func (s *Server) ReadIsCommitteeMember(_ context.Context, accountInfoRequest *inx.AccountInfoRequest) (*inx.BoolResponse, error) {
slot := iotago.SlotIndex(accountInfoRequest.GetAccountSlot())
accountID, _, err := iotago.AccountIDFromBytes(accountInfoRequest.AccountId)
if err != nil {
return nil, ierrors.Wrap(err, "error when parsing account id")
}
committee, exists := deps.Protocol.MainEngineInstance().SybilProtection.SeatManager().CommitteeInSlot(slot)
if !exists {
return nil, ierrors.Errorf("committee does not exist for slot %d", slot)
}

return inx.WrapBoolResponse(committee.HasAccount(accountID)), nil
}

func (s *Server) ReadIsCandidate(_ context.Context, accountInfoRequest *inx.AccountInfoRequest) (*inx.BoolResponse, error) {
slot := iotago.SlotIndex(accountInfoRequest.GetAccountSlot())
accountID, _, err := iotago.AccountIDFromBytes(accountInfoRequest.AccountId)
if err != nil {
return nil, ierrors.Wrap(err, "error when parsing account id")
}

isCandidateActive, err := deps.Protocol.MainEngineInstance().SybilProtection.IsCandidateActive(accountID, deps.Protocol.APIForSlot(slot).TimeProvider().EpochFromSlot(slot))
if err != nil {
return nil, ierrors.Wrap(err, "error when checking if candidate is active")
}

return inx.WrapBoolResponse(isCandidateActive), nil
}
6 changes: 6 additions & 0 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import (
iotago "github.com/iotaledger/iota.go/v4"
)

func (s *Server) ReadActiveRootBlocks(_ context.Context, _ *inx.NoParams) (*inx.RootBlocksResponse, error) {
activeRootBlocks := deps.Protocol.MainEngineInstance().EvictionState.ActiveRootBlocks()

return inx.WrapRootBlocks(activeRootBlocks), nil
}

func (s *Server) ReadBlock(_ context.Context, blockID *inx.BlockId) (*inx.RawBlock, error) {
blkID := blockID.Unwrap()
block, exists := deps.Protocol.MainEngineInstance().Block(blkID) // block +1
Expand Down
8 changes: 8 additions & 0 deletions components/inx/server_commitments.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func inxCommitment(commitment *model.Commitment) *inx.Commitment {
}
}

func (s *Server) ForceCommitUntil(_ context.Context, slot *inx.SlotIndex) (*inx.NoParams, error) {
err := deps.Protocol.MainEngineInstance().Notarization.ForceCommitUntil(slot.Unwrap())
if err != nil {
return nil, ierrors.Wrapf(err, "error while performing force commit until %d", slot.Index)
}

return &inx.NoParams{}, nil
}
func (s *Server) ReadCommitment(_ context.Context, req *inx.CommitmentRequest) (*inx.Commitment, error) {
commitmentSlot := iotago.SlotIndex(req.GetCommitmentSlot())

Expand Down
1 change: 1 addition & 0 deletions components/inx/server_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func inxNodeStatus(status *syncmanager.SyncStatus) *inx.NodeStatus {

return &inx.NodeStatus{
IsHealthy: status.NodeSynced,
IsBootstrapped: status.NodeBootstrapped,
LastAcceptedBlockSlot: uint32(status.LastAcceptedBlockSlot),
LastConfirmedBlockSlot: uint32(status.LastConfirmedBlockSlot),
LatestCommitment: inxCommitment(status.LatestCommitment),
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/collector/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (m *Metric) schedulePruning(labelValues []string) {

func (m *Metric) shutdown() {
if m.pruningExecutor != nil {
m.pruningExecutor.Shutdown()
m.pruningExecutor.Shutdown(timed.CancelPendingElements)
}
}

Expand Down
19 changes: 12 additions & 7 deletions components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) {
}, nil
}

func selectedCommittee(c echo.Context) *apimodels.CommitteeResponse {
func selectedCommittee(c echo.Context) (*apimodels.CommitteeResponse, error) {
timeProvider := deps.Protocol.CommittedAPI().TimeProvider()

var slot iotago.SlotIndex
Expand All @@ -206,11 +206,16 @@ func selectedCommittee(c echo.Context) *apimodels.CommitteeResponse {
if !exists {
return &apimodels.CommitteeResponse{
Epoch: epoch,
}
}, nil
}

accounts, err := seatedAccounts.Accounts()
if err != nil {
return nil, ierrors.Wrapf(err, "failed to get accounts from committee for slot %d", slot)
}

committee := make([]*apimodels.CommitteeMemberResponse, 0, seatedAccounts.Accounts().Size())
seatedAccounts.Accounts().ForEach(func(accountID iotago.AccountID, seat *account.Pool) bool {
committee := make([]*apimodels.CommitteeMemberResponse, 0, accounts.Size())
accounts.ForEach(func(accountID iotago.AccountID, seat *account.Pool) bool {
committee = append(committee, &apimodels.CommitteeMemberResponse{
AccountID: accountID,
PoolStake: seat.PoolStake,
Expand All @@ -224,7 +229,7 @@ func selectedCommittee(c echo.Context) *apimodels.CommitteeResponse {
return &apimodels.CommitteeResponse{
Epoch: epoch,
Committee: committee,
TotalStake: seatedAccounts.Accounts().TotalStake(),
TotalValidatorStake: seatedAccounts.Accounts().TotalValidatorStake(),
}
TotalStake: accounts.TotalStake(),
TotalValidatorStake: accounts.TotalValidatorStake(),
}, nil
}
2 changes: 1 addition & 1 deletion components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func blockMetadataByID(c echo.Context) (*apimodels.BlockMetadataResponse, error)
}

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

var slotCommitment *model.Commitment
var err error
Expand Down
5 changes: 4 additions & 1 deletion components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ func configure() error {
}, checkNodeSynced())

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

return responseByHeader(c, resp)
}, checkNodeSynced())
Expand Down
93 changes: 0 additions & 93 deletions components/validator/component.go

This file was deleted.

Loading

0 comments on commit 9e59adb

Please sign in to comment.