Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diego/chain upgrade v0.4.0 fixes PROTO-2352 #53

Merged
merged 12 commits into from
Sep 18, 2024
30 changes: 27 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* [#31](https://github.com/allora-network/allora-offchain-node/pull/31) SubmitTx fix: if set to false but properly configured, it should still not submit.
### Added

* [#53](https://github.com/allora-network/allora-offchain-node/pull/53) Update to v0.5.0 chain dependencies. Validate bundles before sending.

### Removed

### Fixed

* [#55](https://github.com/allora-network/allora-offchain-node/pull/55) Passive set retrial optimization.

### Security

## v0.3.0

### Added

* [#41](https://github.com/allora-network/allora-offchain-node/pull/41) MSE insteead of MAE, Reputer data validation, refactoring.
* [#42](https://github.com/allora-network/allora-offchain-node/pull/41) Update to v0.4.0 version of the chain. This contains breaking changes in types.

### Removed

### Fixed

* [#37](https://github.com/allora-network/allora-offchain-node/pull/37) Fix covering nil pointer when params are not available
* [#38](https://github.com/allora-network/allora-offchain-node/pull/38) Fix error handling (nil pointer dereference) on registration.
* [#40](https://github.com/allora-network/allora-offchain-node/pull/40) Forecasting fixes
* [#41](https://github.com/allora-network/allora-offchain-node/pull/41) MSE insteead of MAE, Reputer data validation, refactoring.
* [#42](https://github.com/allora-network/allora-offchain-node/pull/41) Update to v0.4.0 version of the chain. This contains breaking changes in types.
* [#31](https://github.com/allora-network/allora-offchain-node/pull/31) SubmitTx fix: if set to false but properly configured, it should still not submit.


### Security

## v0.2.0

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go 1.22.5

require (
cosmossdk.io/math v1.3.0
github.com/allora-network/allora-chain v0.4.0
github.com/allora-network/allora-chain v0.4.1-0.20240918065232-f9a29f147678
github.com/cosmos/cosmos-sdk v0.50.8
github.com/ignite/cli/v28 v28.5.0
github.com/joho/godotenv v1.5.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/allora-network/allora-chain v0.4.0 h1:1vhjyoa+0DIZoSIheK8NqHNqhUkRc0RZ8uzpcQm863c=
github.com/allora-network/allora-chain v0.4.0/go.mod h1:Mc6EjLiTIzHFYazLNEUkk394U0xHOQFE9XD3LxllXKI=
github.com/allora-network/allora-chain v0.4.1-0.20240913115114-ba99e28ccd08 h1:SweCd+3X3UbG4ardbU8lNKDvpiRRO3/L1ka/D9POb/M=
github.com/allora-network/allora-chain v0.4.1-0.20240913115114-ba99e28ccd08/go.mod h1:Mc6EjLiTIzHFYazLNEUkk394U0xHOQFE9XD3LxllXKI=
github.com/allora-network/allora-chain v0.4.1-0.20240918065232-f9a29f147678 h1:2stPIEpiKC/rRGrbKpt+u0VDmg/x9qBt/qyVLup+sNw=
github.com/allora-network/allora-chain v0.4.1-0.20240918065232-f9a29f147678/go.mod h1:Mc6EjLiTIzHFYazLNEUkk394U0xHOQFE9XD3LxllXKI=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down
2 changes: 1 addition & 1 deletion lib/domain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ChainConfig struct {
Address string // will be auto-generated based on the keystore
Account cosmosaccount.Account
Client *cosmosclient.Client
EmissionsQueryClient emissions.QueryClient
EmissionsQueryClient emissions.QueryServiceClient
BankQueryClient bank.QueryClient
DefaultBondDenom string
AddressPrefix string // prefix for the allora addresses
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (config *UserConfig) GenerateNodeConfig() (*NodeConfig, error) {
}

// Create query client
queryClient := emissionstypes.NewQueryClient(client.Context())
queryClient := emissionstypes.NewQueryServiceClient(client.Context())

// Create bank client
bankClient := banktypes.NewQueryClient(client.Context())
Expand Down
6 changes: 3 additions & 3 deletions lib/repo_query_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
func (node *NodeConfig) GetReputerValuesAtBlock(topicId emissionstypes.TopicId, nonce BlockHeight) (*emissionstypes.ValueBundle, error) {
ctx := context.Background()

req := &emissionstypes.QueryNetworkInferencesAtBlockRequest{
req := &emissionstypes.GetNetworkInferencesAtBlockRequest{
TopicId: topicId,
BlockHeightLastInference: nonce,
}
reqJSON, err := json.Marshal(req)
if err != nil {
log.Error().Err(err).Msg("Error marshaling QueryNetworkInferencesAtBlockRequest to print Msg as JSON")
log.Error().Err(err).Msg("Error marshaling GetNetworkInferencesAtBlockRequest to print Msg as JSON")
} else {
log.Info().Str("req", string(reqJSON)).Msg("Getting QueryNetworkInferencesAtBlockRequest from chain")
log.Info().Str("req", string(reqJSON)).Msg("Getting GetNetworkInferencesAtBlockRequest from chain")
}

res, err := node.Chain.EmissionsQueryClient.GetNetworkInferencesAtBlock(ctx, req)
Expand Down
4 changes: 2 additions & 2 deletions lib/repo_query_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (node *NodeConfig) GetLatestOpenWorkerNonceByTopicId(topicId emissionstypes

res, err := node.Chain.EmissionsQueryClient.GetUnfulfilledWorkerNonces(
ctx,
&emissionstypes.QueryUnfulfilledWorkerNoncesRequest{TopicId: topicId},
&emissionstypes.GetUnfulfilledWorkerNoncesRequest{TopicId: topicId},
)
if err != nil {
return &emissionstypes.Nonce{}, err
Expand All @@ -29,7 +29,7 @@ func (node *NodeConfig) GetOldestReputerNonceByTopicId(topicId emissionstypes.To

res, err := node.Chain.EmissionsQueryClient.GetUnfulfilledReputerNonces(
ctx,
&emissionstypes.QueryUnfulfilledReputerNoncesRequest{TopicId: topicId},
&emissionstypes.GetUnfulfilledReputerNoncesRequest{TopicId: topicId},
)
if err != nil {
return 0, err
Expand Down
8 changes: 4 additions & 4 deletions lib/repo_query_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ func (node *NodeConfig) IsWorkerRegistered(topicId uint64) (bool, error) {
ctx := context.Background()

var (
res *emissionstypes.QueryIsWorkerRegisteredInTopicIdResponse
res *emissionstypes.IsWorkerRegisteredInTopicIdResponse
err error
)

if node.Worker != nil {
res, err = node.Chain.EmissionsQueryClient.IsWorkerRegisteredInTopicId(ctx, &emissionstypes.QueryIsWorkerRegisteredInTopicIdRequest{
res, err = node.Chain.EmissionsQueryClient.IsWorkerRegisteredInTopicId(ctx, &emissionstypes.IsWorkerRegisteredInTopicIdRequest{
TopicId: topicId,
Address: node.Wallet.Address,
})
Expand All @@ -35,12 +35,12 @@ func (node *NodeConfig) IsReputerRegistered(topicId uint64) (bool, error) {
ctx := context.Background()

var (
res *emissionstypes.QueryIsReputerRegisteredInTopicIdResponse
res *emissionstypes.IsReputerRegisteredInTopicIdResponse
err error
)

if node.Reputer != nil {
res, err = node.Chain.EmissionsQueryClient.IsReputerRegisteredInTopicId(ctx, &emissionstypes.QueryIsReputerRegisteredInTopicIdRequest{
res, err = node.Chain.EmissionsQueryClient.IsReputerRegisteredInTopicId(ctx, &emissionstypes.IsReputerRegisteredInTopicIdRequest{
TopicId: topicId,
Address: node.Wallet.Address,
})
Expand Down
2 changes: 1 addition & 1 deletion lib/repo_query_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (node *NodeConfig) GetReputerStakeInTopic(
reputer Address,
) (cosmossdk_io_math.Int, error) {
ctx := context.Background()
resp, err := node.Chain.EmissionsQueryClient.GetStakeFromReputerInTopicInSelf(ctx, &emissionstypes.QueryStakeFromReputerInTopicInSelfRequest{
resp, err := node.Chain.EmissionsQueryClient.GetStakeFromReputerInTopicInSelf(ctx, &emissionstypes.GetStakeFromReputerInTopicInSelfRequest{
ReputerAddress: reputer,
TopicId: topicId,
})
Expand Down
15 changes: 6 additions & 9 deletions lib/repo_tx_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (node *NodeConfig) RegisterWorkerIdempotently(config WorkerConfig) bool {
return true
}

moduleParams, err := node.Chain.EmissionsQueryClient.Params(ctx, &emissionstypes.QueryParamsRequest{})
moduleParams, err := node.Chain.EmissionsQueryClient.GetParams(ctx, &emissionstypes.GetParamsRequest{})
if err != nil {
log.Error().Err(err).Msg("Could not get chain params for worker ")
return false
Expand All @@ -39,7 +39,7 @@ func (node *NodeConfig) RegisterWorkerIdempotently(config WorkerConfig) bool {
return false
}

msg := &emissionstypes.MsgRegister{
msg := &emissionstypes.RegisterRequest{
Sender: node.Chain.Address,
TopicId: config.TopicId,
Owner: node.Chain.Address,
Expand Down Expand Up @@ -67,18 +67,15 @@ func (node *NodeConfig) RegisterAndStakeReputerIdempotently(config ReputerConfig

if isRegistered {
log.Info().Uint64("topicId", config.TopicId).Msg("Reputer node already registered")
}

if !isRegistered {
} else {
log.Info().Uint64("topicId", config.TopicId).Msg("Reputer node not yet registered. Attempting registration...")

balance, err := node.GetBalance()
if err != nil {
log.Error().Err(err).Msg("Could not check if the Reputer node has enough balance to register, skipping")
return false
}

moduleParams, err := node.Chain.EmissionsQueryClient.Params(ctx, &emissionstypes.QueryParamsRequest{})
moduleParams, err := node.Chain.EmissionsQueryClient.GetParams(ctx, &emissionstypes.GetParamsRequest{})
if err != nil {
log.Error().Err(err).Msg("Could not get chain params for reputer")
return false
Expand All @@ -88,7 +85,7 @@ func (node *NodeConfig) RegisterAndStakeReputerIdempotently(config ReputerConfig
return false
}

msgRegister := &emissionstypes.MsgRegister{
msgRegister := &emissionstypes.RegisterRequest{
Sender: node.Chain.Address,
TopicId: config.TopicId,
Owner: node.Chain.Address,
Expand All @@ -114,7 +111,7 @@ func (node *NodeConfig) RegisterAndStakeReputerIdempotently(config ReputerConfig
return true
}

msgAddStake := &emissionstypes.MsgAddStake{
msgAddStake := &emissionstypes.AddStakeRequest{
Sender: node.Wallet.Address,
Amount: minStake.Sub(stake),
TopicId: config.TopicId,
Expand Down
5 changes: 5 additions & 0 deletions lib/repo_tx_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lib

import (
"context"
"strings"
"time"

"github.com/rs/zerolog/log"
Expand All @@ -22,6 +23,10 @@ func (node *NodeConfig) SendDataWithRetry(ctx context.Context, req sdktypes.Msg,
log.Debug().Str("msg", successMsg).Str("txHash", txResp.TxHash).Msg("Success")
return txResp, nil
}
if strings.Contains(err.Error(), "cannot update EMA") {
log.Error().Err(err).Str("msg", successMsg).Msg("Already sent data for this epoch, no retry")
return nil, err
}
// Log the error for each retry.
log.Error().Err(err).Str("msg", successMsg).Msgf("Failed, retrying... (Retry %d/%d)", retryCount, node.Wallet.MaxRetries)
// Wait for the uniform delay before retrying
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"

"github.com/joho/godotenv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -52,8 +51,9 @@ func main() {
log.Info().Msg("Unable to load .env file")
}

// UNIX Time is faster and smaller than most timestamps
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
// UNIX Time is faster and smaller than most timestamps,
// uncomment below line to improve efficiency over human readability
// zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Info().Msg("Starting allora offchain node...")

metrics := lib.NewMetrics(lib.COUNTER_DATA)
Expand Down
8 changes: 6 additions & 2 deletions usecase/build_commit_reputer_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ func (suite *UseCaseSuite) BuildCommitReputerPayload(reputer lib.ReputerConfig,
return false, err
}

req := &emissionstypes.MsgInsertReputerPayload{
if err := signedValueBundle.Validate(); err != nil {
return false, err
}

req := &emissionstypes.InsertReputerPayloadRequest{
Sender: suite.Node.Wallet.Address,
ReputerValueBundle: signedValueBundle,
}
reqJSON, err := json.Marshal(req)
if err != nil {
log.Error().Err(err).Uint64("topicId", reputer.TopicId).Msgf("Error marshaling MsgInserReputerPayload to print Msg as JSON")
} else {
log.Debug().Uint64("topicId", reputer.TopicId).Msgf("Sending MsgInsertReputerPayload to chain %s", string(reqJSON))
log.Debug().Uint64("topicId", reputer.TopicId).Msgf("Sending InsertReputerPayload to chain %s", string(reqJSON))
}
if suite.Node.Wallet.SubmitTx {
_, err = suite.Node.SendDataWithRetry(ctx, req, "Send Reputer Data to chain")
Expand Down
10 changes: 7 additions & 3 deletions usecase/build_commit_worker_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,19 @@ func (suite *UseCaseSuite) BuildCommitWorkerPayload(worker lib.WorkerConfig, non
workerDataBundle.Nonce = nonce
workerDataBundle.TopicId = worker.TopicId

req := &emissionstypes.MsgInsertWorkerPayload{
if err := workerDataBundle.Validate(); err != nil {
return false, err
}

req := &emissionstypes.InsertWorkerPayloadRequest{
Sender: suite.Node.Wallet.Address,
WorkerDataBundle: workerDataBundle,
}
reqJSON, err := json.Marshal(req)
if err != nil {
log.Error().Err(err).Msg("Error marshaling MsgInsertWorkerPayload to print Msg as JSON")
log.Error().Err(err).Msg("Error marshaling InsertWorkerPayload to print Msg as JSON")
} else {
log.Info().Str("req", string(reqJSON)).Msg("Sending MsgInsertWorkerPayload to chain")
log.Info().Str("req", string(reqJSON)).Msg("Sending InsertWorkerPayload to chain")
}

if suite.Node.Wallet.SubmitTx {
Expand Down