diff --git a/core/go.mod b/core/go.mod index b7a6d76..70bba9a 100644 --- a/core/go.mod +++ b/core/go.mod @@ -8,14 +8,17 @@ require ( github.com/cilium/ipam v0.0.0-20230509084518-fd66eae7909b github.com/cometbft/cometbft v0.38.12 github.com/cosmos/cosmos-sdk v0.50.10 + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/digitalocean/godo v1.108.0 github.com/docker/docker v27.1.1+incompatible github.com/docker/go-connections v0.4.0 github.com/go-rod/rod v0.114.6 github.com/golangci/golangci-lint v1.56.2 + github.com/matoous/go-nanoid/v2 v2.1.0 + github.com/ory/dockertest v3.3.5+incompatible github.com/pkg/errors v0.9.1 github.com/pkg/sftp v1.13.6 - github.com/puzpuzpuz/xsync/v3 v3.0.2 + github.com/puzpuzpuz/xsync/v3 v3.4.0 github.com/spf13/afero v1.11.0 github.com/stretchr/testify v1.9.0 go.uber.org/zap v1.26.0 @@ -95,7 +98,6 @@ require ( github.com/curioswitch/go-reassign v0.2.0 // indirect github.com/daixiang0/gci v0.12.1 // indirect github.com/danieljoos/wincred v1.1.2 // indirect - github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/denis-tingaikin/go-header v0.4.3 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect diff --git a/core/go.sum b/core/go.sum index 969eff1..02f75cb 100644 --- a/core/go.sum +++ b/core/go.sum @@ -570,6 +570,8 @@ github.com/gostaticanalysis/nilerr v0.1.1/go.mod h1:wZYb6YI5YAxxq0i1+VJbY0s2YONW github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M= github.com/gostaticanalysis/testutil v0.4.0 h1:nhdCmubdmDF6VEatUNjgUZBJKWRqugoISdUv3PPQgHY= github.com/gostaticanalysis/testutil v0.4.0/go.mod h1:bLIoPefWXrRi/ssLFWX1dx7Repi5x3CuviD3dgAZaBU= +github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:AQwinXlbQR2HvPjQZOmDhRqsv5mZf+Jb1RnSLxcqZcI= +github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= @@ -741,6 +743,8 @@ github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE= github.com/maratori/testpackage v1.1.1 h1:S58XVV5AD7HADMmD0fNnziNHqKvSdDuEKdPD1rNTU04= github.com/maratori/testpackage v1.1.1/go.mod h1:s4gRK/ym6AMrqpOa/kEbQTV4Q4jb7WeLZzVhVVVOQMc= +github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE= +github.com/matoous/go-nanoid/v2 v2.1.0/go.mod h1:KlbGNQ+FhrUNIHUxZdL63t7tl4LaPkZNpUULS8H4uVM= github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 h1:gWg6ZQ4JhDfJPqlo2srm/LN17lpybq15AryXIRcWYLE= github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= @@ -862,6 +866,8 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA= +github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= @@ -937,8 +943,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/puzpuzpuz/xsync/v3 v3.0.2 h1:3yESHrRFYr6xzkz61LLkvNiPFXxJEAABanTQpKbAaew= -github.com/puzpuzpuz/xsync/v3 v3.0.2/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= +github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= +github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/quasilyte/go-ruleguard v0.4.0 h1:DyM6r+TKL+xbKB4Nm7Afd1IQh9kEUKQs2pboWGKtvQo= github.com/quasilyte/go-ruleguard v0.4.0/go.mod h1:Eu76Z/R8IXtViWUIHkE3p8gdH3/PKk1eh3YGfaEof10= github.com/quasilyte/gogrep v0.5.0 h1:eTKODPXbI8ffJMN+W2aE0+oL0z/nh8/5eNdiO34SOAo= @@ -1651,6 +1657,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/core/provider/definitions.go b/core/provider/definitions.go index 42865f2..13e896f 100644 --- a/core/provider/definitions.go +++ b/core/provider/definitions.go @@ -40,7 +40,6 @@ type TaskDefinition struct { Entrypoint []string Command []string Args []string - Sidecars []TaskDefinition ProviderSpecificConfig interface{} } @@ -73,12 +72,6 @@ func (t *TaskDefinition) ValidateBasic() error { } } - for _, v := range t.Sidecars { - if err := v.ValidateBasic(); err != nil { - return fmt.Errorf("sidecar is invalid: %w", err) - } - } - return nil } diff --git a/core/provider/definitions_test.go b/core/provider/definitions_test.go index f1b872a..e6c508b 100644 --- a/core/provider/definitions_test.go +++ b/core/provider/definitions_test.go @@ -176,20 +176,6 @@ func TestTaskDefinitionValidation(t *testing.T) { }, expectPass: false, }, - { - name: "invalid sidecar", - def: provider.TaskDefinition{ - Name: "test", - ContainerName: "test", - Image: validImageDefinition, - Sidecars: []provider.TaskDefinition{ - { - Name: "test", - }, - }, - }, - expectPass: false, - }, } for _, tc := range tcs { diff --git a/core/provider/provider.go b/core/provider/provider.go index 0fd099a..479ff13 100644 --- a/core/provider/provider.go +++ b/core/provider/provider.go @@ -23,7 +23,6 @@ type Task struct { ID string Definition TaskDefinition - Sidecars []*Task logger *zap.Logger mu sync.RWMutex diff --git a/core/provider/task.go b/core/provider/task.go index 76d1ad1..ab107b6 100644 --- a/core/provider/task.go +++ b/core/provider/task.go @@ -2,7 +2,6 @@ package provider import ( "context" - "errors" "fmt" "golang.org/x/sync/errgroup" "sync" @@ -10,7 +9,7 @@ import ( "go.uber.org/zap" ) -// CreateTask creates a task structure and sets up its underlying workload on a provider, including sidecars if there are any in the definition +// CreateTask creates a task structure and sets up its underlying workload on a provider func CreateTask(ctx context.Context, logger *zap.Logger, provider Provider, definition TaskDefinition) (*Task, error) { if err := definition.ValidateBasic(); err != nil { return nil, fmt.Errorf("failed to validate task definition: %w", err) @@ -26,67 +25,30 @@ func CreateTask(ctx context.Context, logger *zap.Logger, provider Provider, defi task.mu.Lock() defer task.mu.Unlock() - sidecarTasks := make([]*Task, 0) - var eg errgroup.Group - for i := range definition.Sidecars { - sidecar := definition.Sidecars[i] - eg.Go(func() error { - if len(sidecar.Sidecars) > 0 { - return errors.New("sidecar cannot have sidecar") - } - - id, err := provider.CreateTask(ctx, task.logger, sidecar) - if err != nil { - return err - } - - sidecarTasks = append(sidecarTasks, &Task{ - Provider: provider, - Definition: sidecar, - ID: id, - Sidecars: make([]*Task, 0), - logger: task.logger, - }) - - return nil - }) - } - - eg.Go(func() error { id, err := provider.CreateTask(ctx, logger, definition) if err != nil { return err } - + task.ID = id - + return nil }) - + if err := eg.Wait(); err != nil { return nil, err } - - task.Sidecars = sidecarTasks + return task, nil } -// Start starts the underlying task's workload including its sidecars if startSidecars is set to true. +// Start starts the underlying task's workload // This method does not take a lock on the provider, hence 2 threads may simultaneously call Start on the same task, // this is not thread-safe: PLEASE DON'T DO THAT. func (t *Task) Start(ctx context.Context, startSidecars bool) error { - if startSidecars { - for _, sidecar := range t.Sidecars { - err := sidecar.Start(ctx, startSidecars) - if err != nil { - return err - } - } - } - if t.PreStart != nil { err := t.PreStart(ctx, t) if err != nil { @@ -102,20 +64,11 @@ func (t *Task) Start(ctx context.Context, startSidecars bool) error { return nil } -// Stop stops the underlying task's workload including its sidecars if stopSidecars is set to true +// Stop stops the underlying task's workload func (t *Task) Stop(ctx context.Context, stopSidecars bool) error { t.mu.Lock() defer t.mu.Unlock() - if stopSidecars { - for _, sidecar := range t.Sidecars { - err := sidecar.Stop(ctx, stopSidecars) - if err != nil { - return err - } - } - } - err := t.Provider.StopTask(ctx, t.ID) if t.PostStop != nil { @@ -203,20 +156,11 @@ func (t *Task) GetStatus(ctx context.Context) (TaskStatus, error) { return t.Provider.GetTaskStatus(ctx, t.ID) } -// Destroy destroys the task's underlying workload, including it's sidecars if destroySidecars is set to true +// Destroy destroys the task's underlying workload func (t *Task) Destroy(ctx context.Context, destroySidecars bool) error { t.mu.Lock() defer t.mu.Unlock() - if destroySidecars { - for _, sidecar := range t.Sidecars { - err := sidecar.Destroy(ctx, destroySidecars) - if err != nil { - return err - } - } - } - err := t.Provider.DestroyTask(ctx, t.ID) if err != nil { return err diff --git a/core/types/chain.go b/core/types/chain.go index 5fb11f7..1ab65e7 100644 --- a/core/types/chain.go +++ b/core/types/chain.go @@ -40,7 +40,7 @@ type ChainI interface { } // ChainConfig is the configuration structure for a logical chain. -// It contains all the relevant details needed to create a Cosmos chain and it's sidecars +// It contains all the relevant details needed to create a Cosmos chain type ChainConfig struct { Denom string // Denom is the denomination of the native staking token Decimals uint64 // Decimals is the number of decimals of the native staking token @@ -49,8 +49,7 @@ type ChainConfig struct { BinaryName string // BinaryName is the name of the chain binary in the Docker image - Image provider.ImageDefinition // Image is the Docker ImageDefinition of the chain - SidecarImage provider.ImageDefinition // SidecarImage is the Docker ImageDefinition of the chain sidecar + Image provider.ImageDefinition // Image is the Docker ImageDefinition of the chain GasPrices string // GasPrices are the minimum gas prices to set on the chain GasAdjustment float64 // GasAdjustment is the margin by which to multiply the default gas prices @@ -59,10 +58,7 @@ type ChainConfig struct { EncodingConfig testutil.TestEncodingConfig // EncodingConfig is the encoding config of the chain - HomeDir string // HomeDir is the home directory of the chain - SidecarHomeDir string // SidecarHomeDir is the home directory of the chain sidecar - SidecarPorts []string // SidecarPorts are the ports to expose on the chain sidecar - SidecarArgs []string // SidecarArgs are the arguments to launch the chain sidecar + HomeDir string // HomeDir is the home directory of the chain CoinType string // CoinType is the coin type of the chain (e.g. 118) ChainId string // ChainId is the chain ID of the chain @@ -125,12 +121,6 @@ func (c *ChainConfig) ValidateBasic() error { return fmt.Errorf("image definition is invalid: %w", err) } - if c.SidecarImage.Image != "" { - if err := c.SidecarImage.ValidateBasic(); err != nil { - return fmt.Errorf("sidecar image definition is invalid: %w", err) - } - } - if c.Bech32Prefix == "" { return fmt.Errorf("bech32 prefix cannot be empty") } diff --git a/core/types/node.go b/core/types/node.go index f916479..332912d 100644 --- a/core/types/node.go +++ b/core/types/node.go @@ -40,7 +40,7 @@ func (c NodeConfig) ValidateBasic() error { } // NodeDefinitionModifier is a type of function that given a NodeConfig modifies the task definition. It usually -// adds additional sidecars or modifies the entrypoint. This function is typically called in NodeCreator +// modifies the entrypoint. This function is typically called in NodeCreator // before the task is created type NodeDefinitionModifier func(provider.TaskDefinition, NodeConfig) provider.TaskDefinition diff --git a/cosmos/node/config.go b/cosmos/node/config.go index 58c4041..7308ff1 100644 --- a/cosmos/node/config.go +++ b/cosmos/node/config.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - toml "github.com/pelletier/go-toml/v2" + "github.com/pelletier/go-toml/v2" petritypes "github.com/skip-mev/petri/core/v2/types" "reflect" diff --git a/cosmos/node/node.go b/cosmos/node/node.go index b59bc79..0f81a58 100644 --- a/cosmos/node/node.go +++ b/cosmos/node/node.go @@ -44,25 +44,11 @@ func CreateNode(ctx context.Context, logger *zap.Logger, nodeConfig petritypes.N chainConfig := nodeConfig.Chain.GetConfig() - var sidecars []provider.TaskDefinition - - if chainConfig.SidecarHomeDir != "" { - sidecars = append(sidecars, provider.TaskDefinition{ - Name: fmt.Sprintf("%s-sidecar-%d", nodeConfig.Name, 0), // todo(Zygimantass): fix this to support multiple sidecars - ContainerName: fmt.Sprintf("%s-sidecar-%d", nodeConfig.Name, 0), - Image: chainConfig.SidecarImage, - DataDir: chainConfig.SidecarHomeDir, - Ports: chainConfig.SidecarPorts, - Entrypoint: chainConfig.SidecarArgs, - }) - } - def := provider.TaskDefinition{ Name: nodeConfig.Name, ContainerName: nodeConfig.Name, Image: chainConfig.Image, Ports: []string{"9090", "26656", "26657", "26660", "80"}, - Sidecars: sidecars, Entrypoint: []string{chainConfig.BinaryName, "--home", chainConfig.HomeDir, "start"}, DataDir: chainConfig.HomeDir, } diff --git a/cosmos/types/types.go b/cosmos/types/types.go new file mode 100644 index 0000000..544e78d --- /dev/null +++ b/cosmos/types/types.go @@ -0,0 +1,8 @@ +package types + +import "math/big" + +type Coin struct { + Amount big.Int + Denom string +} diff --git a/go.mod b/go.mod index 1ad648c..2bd1c2a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/skip-mev/petri -go 1.21.3 +go 1.22.0 require ( github.com/client9/misspell v0.3.4