Skip to content

Commit

Permalink
Merge branch 'feat/cache-reset' of github.com:iotaledger/iota-core in…
Browse files Browse the repository at this point in the history
…to feat/reactive-chainmanager
  • Loading branch information
hmoog committed Nov 2, 2023
2 parents 0c33362 + a5df392 commit 16ce5ce
Show file tree
Hide file tree
Showing 193 changed files with 5,191 additions and 11,063 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/build_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ name: Build internal tools
on:
pull_request:
paths:
- 'tools/evil-spammer/**'
- 'tools/genesis-snapshot/**'
jobs:

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

- name: Checkout repository
Expand All @@ -23,10 +22,6 @@ jobs:
- name: Print Go version
run: go version

- name: Build evil-spammer tool
working-directory: tools/evil-spammer
run: go mod tidy && go build .

- name: Build genesis-snapshot tool
working-directory: tools/genesis-snapshot
run: go mod tidy && go build .
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
6 changes: 1 addition & 5 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 All @@ -30,6 +29,3 @@ dist/
# snapshot and settings file
*.bin
tools/docker-network/docker-network.snapshot
tools/evil-spammer/evil-spammer


2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ run:
tests: true
skip-dirs:
- components/dashboard
- tools/evilwallet
- tools/evil-spammer
skip-files:
- ".*_test.go$"
- "testframework.go"
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ RUN cp ./peering.json /app/peering.json
# using distroless cc "nonroot" image, which includes everything in the base image (glibc, libssl and openssl)
FROM gcr.io/distroless/cc-debian12:nonroot

HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD ["/app/iota-core", "tools", "node-info"]

# Copy the app dir into distroless image
COPY --chown=nonroot:nonroot --from=build /app /app

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ RUN mkdir -p /app/data/peerdb
# using distroless cc "nonroot" image, which includes everything in the base image (glibc, libssl and openssl)
FROM gcr.io/distroless/cc-debian12:nonroot

HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD ["/app/iota-core", "tools", "node-info"]

# Copy the app dir into distroless image
COPY --chown=nonroot:nonroot --from=build /app /app

Expand Down
22 changes: 20 additions & 2 deletions components/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app

import (
"fmt"
"os"

"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/components/profiling"
"github.com/iotaledger/hive.go/app/components/shutdown"
Expand All @@ -14,7 +17,7 @@ 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"
)

var (
Expand All @@ -28,6 +31,12 @@ var (
func App() *app.App {
return app.New(Name, Version,
// app.WithVersionCheck("iotaledger", "iota-core"),
app.WithUsageText(fmt.Sprintf(`Usage of %s (%s %s):
Run '%s tools' to list all available tools.
Command line flags:
`, os.Args[0], Name, Version, os.Args[0])),
app.WithInitComponent(InitComponent),
app.WithComponents(
shutdown.Component,
Expand All @@ -38,7 +47,6 @@ func App() *app.App {
debugapi.Component,
metricstracker.Component,
protocol.Component,
validator.Component,
dashboardmetrics.Component,
dashboard.Component,
metrics.Component,
Expand All @@ -63,5 +71,15 @@ func init() {
AdditionalConfigs: []*app.ConfigurationSet{
app.NewConfigurationSet("peering", "peering", "peeringConfigFilePath", "peeringConfig", false, true, false, "peering.json", "n"),
},
Init: initialize,
}
}

func initialize(_ *app.App) error {
if toolset.ShouldHandleTools() {
toolset.HandleTools()
// HandleTools will call os.Exit
}

return nil
}
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.Engines.Main.Get().SyncManager.IsBootstrapped(),
Bootstrapped: syncStatus.NodeBootstrapped,
AcceptedBlockSlot: int64(syncStatus.LastAcceptedBlockSlot),
ConfirmedBlockSlot: int64(syncStatus.LastConfirmedBlockSlot),
CommittedSlot: int64(syncStatus.LatestCommitment.Slot()),
Expand Down
20 changes: 10 additions & 10 deletions components/dashboard/explorer_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata
var payloadJSON []byte
basicBlock, isBasic := block.BasicBlock()
if isBasic {
payloadJSON, err = lo.PanicOnErr(deps.Protocol.APIForVersion(iotaBlk.ProtocolVersion)).JSONEncode(basicBlock.Payload)
payloadJSON, err = lo.PanicOnErr(deps.Protocol.APIForVersion(iotaBlk.Header.ProtocolVersion)).JSONEncode(basicBlock.Payload)
if err != nil {
return nil
}
}

t := &ExplorerBlock{
ID: block.ID().ToHex(),
NetworkID: iotaBlk.NetworkID,
ProtocolVersion: iotaBlk.ProtocolVersion,
NetworkID: iotaBlk.Header.NetworkID,
ProtocolVersion: iotaBlk.Header.ProtocolVersion,
SolidificationTimestamp: 0,
IssuanceTimestamp: iotaBlk.IssuingTime.Unix(),
IssuanceTimestamp: iotaBlk.Header.IssuingTime.Unix(),
SequenceNumber: 0,
IssuerID: iotaBlk.IssuerID.ToHex(),
IssuerID: iotaBlk.Header.IssuerID.ToHex(),
Signature: hexutil.EncodeHex(sigBytes),
StrongParents: iotaBlk.Block.StrongParentIDs().ToHex(),
WeakParents: iotaBlk.Block.WeakParentIDs().ToHex(),
ShallowLikedParents: iotaBlk.Block.ShallowLikeParentIDs().ToHex(),
StrongParents: iotaBlk.Body.StrongParentIDs().ToHex(),
WeakParents: iotaBlk.Body.WeakParentIDs().ToHex(),
ShallowLikedParents: iotaBlk.Body.ShallowLikeParentIDs().ToHex(),

PayloadType: func() iotago.PayloadType {
if isBasic && basicBlock.Payload != nil {
Expand Down Expand Up @@ -152,8 +152,8 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata

return ""
}(),
CommitmentID: iotaBlk.SlotCommitmentID.ToHex(),
LatestConfirmedSlot: uint64(iotaBlk.LatestFinalizedSlot),
CommitmentID: iotaBlk.Header.SlotCommitmentID.ToHex(),
LatestConfirmedSlot: uint64(iotaBlk.Header.LatestFinalizedSlot),
}

if cachedBlock != nil {
Expand Down
6 changes: 3 additions & 3 deletions components/dashboard/visualizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func sendVertex(blk *blocks.Block, confirmed bool) {

broadcastWsBlock(&wsblk{MsgTypeVertex, &vertex{
ID: blk.ID().ToHex(),
StrongParents: blk.ProtocolBlock().Block.StrongParentIDs().ToHex(),
WeakParents: blk.ProtocolBlock().Block.WeakParentIDs().ToHex(),
ShallowLikedParents: blk.ProtocolBlock().Block.ShallowLikeParentIDs().ToHex(),
StrongParents: blk.ProtocolBlock().Body.StrongParentIDs().ToHex(),
WeakParents: blk.ProtocolBlock().Body.WeakParentIDs().ToHex(),
ShallowLikedParents: blk.ProtocolBlock().Body.ShallowLikeParentIDs().ToHex(),
IsConfirmed: confirmed,
IsTx: isTx,
IsTxAccepted: func() bool {
Expand Down
4 changes: 2 additions & 2 deletions components/debugapi/debug_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func BlockMetadataResponseFromBlock(block *blocks.Block) *BlockMetadataResponse
return &BlockMetadataResponse{
BlockID: block.ID().String(),
StrongParents: lo.Map(block.StrongParents(), func(blockID iotago.BlockID) string { return blockID.String() }),
WeakParents: lo.Map(block.ProtocolBlock().Block.WeakParentIDs(), func(blockID iotago.BlockID) string { return blockID.String() }),
ShallowLikeParents: lo.Map(block.ProtocolBlock().Block.ShallowLikeParentIDs(), func(blockID iotago.BlockID) string { return blockID.String() }),
WeakParents: lo.Map(block.ProtocolBlock().Body.WeakParentIDs(), func(blockID iotago.BlockID) string { return blockID.String() }),
ShallowLikeParents: lo.Map(block.ProtocolBlock().Body.ShallowLikeParentIDs(), func(blockID iotago.BlockID) string { return blockID.String() }),
Solid: block.IsSolid(),
Invalid: block.IsInvalid(),
Booked: block.IsBooked(),
Expand Down
9 changes: 7 additions & 2 deletions components/debugapi/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package debugapi

import (
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/iota-core/pkg/core/account"
iotago "github.com/iotaledger/iota.go/v4"
Expand All @@ -10,8 +11,12 @@ import (
func validatorsSummary() (*ValidatorsSummaryResponse, error) {
seatManager := deps.Protocol.Engines.Main.Get().SybilProtection.SeatManager()
latestSlotIndex := deps.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot()
latestCommittee := seatManager.Committee(latestSlotIndex)
validatorSeats := []*Validator{}
latestCommittee, exists := seatManager.CommitteeInSlot(latestSlotIndex)
if !exists {
return nil, ierrors.Errorf("committee for slot %d was not selected", latestSlotIndex)
}

var validatorSeats []*Validator
latestCommittee.Accounts().ForEach(func(id iotago.AccountID, pool *account.Pool) bool {
validatorSeats = append(validatorSeats, &Validator{
AccountID: 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.Engines.Main.Get().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.Engines.Main.Get().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.Engines.Main.Get().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
}
18 changes: 12 additions & 6 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.Engines.Main.Get().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.Engines.Main.Get().Block(blkID) // block +1
Expand Down Expand Up @@ -126,7 +132,7 @@ func (s *Server) SubmitBlock(ctx context.Context, rawBlock *inx.RawBlock) (*inx.
return s.attachBlock(ctx, block)
}

func (s *Server) attachBlock(ctx context.Context, block *iotago.ProtocolBlock) (*inx.BlockId, error) {
func (s *Server) attachBlock(ctx context.Context, block *iotago.Block) (*inx.BlockId, error) {
mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped())
defer mergedCtxCancel()

Expand Down Expand Up @@ -154,10 +160,10 @@ func getINXBlockMetadata(blockID iotago.BlockID) (*inx.BlockMetadata, error) {
}

return &inx.BlockMetadata{
BlockId: inx.NewBlockId(blockID),
BlockState: inx.WrapBlockState(blockMetadata.BlockState),
BlockFailureReason: inx.WrapBlockFailureReason(blockMetadata.BlockFailureReason),
TxState: inx.WrapTransactionState(blockMetadata.TxState),
TxFailureReason: inx.WrapTransactionFailureReason(blockMetadata.TxFailureReason),
BlockId: inx.NewBlockId(blockID),
BlockState: inx.WrapBlockState(blockMetadata.BlockState),
BlockFailureReason: inx.WrapBlockFailureReason(blockMetadata.BlockFailureReason),
TransactionState: inx.WrapTransactionState(blockMetadata.TransactionState),
TransactionFailureReason: inx.WrapTransactionFailureReason(blockMetadata.TransactionFailureReason),
}, nil
}
Loading

0 comments on commit 16ce5ce

Please sign in to comment.