Skip to content

Commit

Permalink
integrate Jester + VE's
Browse files Browse the repository at this point in the history
Co-authored-by: John Letey <john@noble.xyz>
  • Loading branch information
boojamya and johnletey committed Jan 11, 2025
1 parent 3e8b1d9 commit 1f00eba
Show file tree
Hide file tree
Showing 13 changed files with 529 additions and 287 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ release/
play_sh/
/heighliner*
bin/
build/
build/
.duke/
131 changes: 131 additions & 0 deletions abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package noble

import (
"context"
"encoding/json"
"fmt"
"math"

"connectrpc.com/connect"
abcitypes "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
wormholekeeper "github.com/noble-assets/wormhole/keeper"
wormholetypes "github.com/noble-assets/wormhole/types"
jester "jester.noble.xyz/api"
)

// InjectedDollarVE is the vote extension data for the Noble Dollar that is injected as a fake transaction into a block.
type InjectedDollarVE struct {
VAAs [][]byte
}

// client queryv1connect.QueryServiceClient
func NewExtendVoteHandler(client jester.QueryServiceClient) sdk.ExtendVoteHandler {
// Returns custom functionality for the block proposer to execute.
return func(ctx sdk.Context, req *abcitypes.RequestExtendVote) (*abcitypes.ResponseExtendVote, error) {
log := ctx.Logger()

request := connect.NewRequest(&jester.GetVoteExtensionRequest{})
res, err := client.GetVoteExtension(context.Background(), request)
if err != nil {
log.Error("failed to get vote extention from jester", "err", err)
}

bz, err := json.Marshal(res.Msg)
if err != nil {
log.Error("failed to marshal vote extention", "err", err)
}

return &abcitypes.ResponseExtendVote{
VoteExtension: bz,
}, err
}
}

func NewVerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandler {
// Returns custom functionality for other validators, not the current proposer, to execute.
return func(ctx sdk.Context, req *abcitypes.RequestVerifyVoteExtension) (*abcitypes.ResponseVerifyVoteExtension, error) {
var voteExtension jester.GetVoteExtensionResponse

err := json.Unmarshal(req.VoteExtension, &voteExtension)
if err != nil {
// NOTE: It is safe to return an error as the Cosmos SDK will capture all
// errors, log them, and reject the proposal.
return nil, fmt.Errorf("failed to unmarshal vote extension: %w", err)

}

ctx.Logger().Info("verifying vote extension", "num_vaas", len(voteExtension.Dollar.Vaas))

return &abcitypes.ResponseVerifyVoteExtension{
Status: abcitypes.ResponseVerifyVoteExtension_ACCEPT,
}, nil
}
}

func NewPrepareProposalHandler() sdk.PrepareProposalHandler {
return func(ctx sdk.Context, req *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error) {
if req.Height <= ctx.ConsensusParams().Abci.VoteExtensionsEnableHeight {
return &abcitypes.ResponsePrepareProposal{Txs: req.Txs}, nil
}

rawVoteExtension := []byte{}
highestPowerVal := int64(math.MinInt64)

for _, vote := range req.LocalLastCommit.Votes {
if vote.Validator.Power > highestPowerVal {
rawVoteExtension = vote.VoteExtension
highestPowerVal = vote.Validator.Power
}
}

var voteExtension jester.GetVoteExtensionResponse
err := json.Unmarshal(rawVoteExtension, &voteExtension)
if err != nil {
return nil, err
}

bz, err := json.Marshal(InjectedDollarVE{
VAAs: voteExtension.Dollar.Vaas,
})
if err != nil {
return nil, err
}
req.Txs = append([][]byte{bz}, req.Txs...)

ctx.Logger().Info("received vote extension", "num_vaas", len(voteExtension.Dollar.Vaas))

return &abcitypes.ResponsePrepareProposal{Txs: req.Txs}, nil
}
}

func NewPreBlocker(wormholeKeeper *wormholekeeper.Keeper) sdk.PreBlocker {
return func(ctx sdk.Context, req *abcitypes.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
res := &sdk.ResponsePreBlock{}
if len(req.Txs) == 0 {
return res, nil
}

var dollarVoteExtension InjectedDollarVE
if err := json.Unmarshal(req.Txs[0], &dollarVoteExtension); err != nil {
ctx.Logger().Error("failed to decode injected dollar vote extension", "err", err)
return nil, err
}

server := wormholekeeper.NewMsgServer(wormholeKeeper)
for _, vaa := range dollarVoteExtension.VAAs {
cachedCtx, writeCache := ctx.CacheContext()
_, err := server.SubmitVAA(cachedCtx, &wormholetypes.MsgSubmitVAA{
Vaa: vaa,
})

if err == nil {
writeCache()
} else {
ctx.Logger().Info("failed to submit VAA", "err", err)
}
}

return res, nil
}
}
10 changes: 10 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"os"
"path/filepath"

"github.com/spf13/cast"

"cosmossdk.io/core/appconfig"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
Expand All @@ -34,6 +36,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/noble-assets/noble/v9/jester"
"github.com/noble-assets/noble/v9/upgrade"

_ "cosmossdk.io/x/evidence"
Expand Down Expand Up @@ -263,6 +266,13 @@ func NewApp(
}
app.SetAnteHandler(anteHandler)

jesterGrpcClient := jester.NewJesterGRPCClient(cast.ToString(appOpts.Get(jester.FlagJesterGRPC)))

app.SetExtendVoteHandler(NewExtendVoteHandler(jesterGrpcClient))
app.SetVerifyVoteExtensionHandler(NewVerifyVoteExtensionHandler())
app.SetPrepareProposal(NewPrepareProposalHandler())
app.SetPreBlocker(NewPreBlocker(app.WormholeKeeper))

if err := app.RegisterUpgradeHandler(); err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/noble-assets/noble/v9"
"github.com/noble-assets/noble/v9/jester"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -53,6 +54,7 @@ func initRootCmd(rootCmd *cobra.Command, txConfig client.TxConfig, basicManager
)

server.AddCommands(rootCmd, noble.DefaultNodeHome, newApp, appExport, func(startCmd *cobra.Command) {
jester.AddJesterFlags(startCmd)
crisis.AddModuleInitFlags(startCmd)
})

Expand Down
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
"github.com/noble-assets/noble/v9/jester"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -76,7 +77,9 @@ func NewRootCmd() *cobra.Command {
cmtCfg := cmtcfg.DefaultConfig()
cmtCfg.Consensus.TimeoutCommit = 500 * time.Millisecond

return server.InterceptConfigsPreRunHandler(cmd, serverconfig.DefaultConfigTemplate, srvCfg, cmtCfg)
customAppTemplate, appConfig := jester.AppendJesterConfig(srvCfg)

return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, appConfig, cmtCfg)
},
}

Expand Down
38 changes: 18 additions & 20 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ require (
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-go/v8 v8.5.2
github.com/docker/docker v24.0.9+incompatible
github.com/ethereum/go-ethereum v1.14.11
github.com/ethereum/go-ethereum v1.14.12
github.com/monerium/module-noble/v2 v2.0.0
github.com/noble-assets/authority v1.0.1
github.com/noble-assets/globalfee v1.0.0
github.com/noble-assets/halo/v2 v2.0.1
github.com/noble-assets/noble/v9 v9.0.0
github.com/ondoprotocol/usdy-noble/v2 v2.0.0
github.com/strangelove-ventures/interchaintest/v8 v8.8.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
go.uber.org/zap v1.27.0
)

require (
cloud.google.com/go v0.115.1 // indirect
cloud.google.com/go/auth v0.9.3 // indirect
cloud.google.com/go/auth v0.9.4 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/compute/metadata v0.5.1 // indirect
cloud.google.com/go/iam v1.2.0 // indirect
cloud.google.com/go/storage v1.43.0 // indirect
cosmossdk.io/api v0.7.6 // indirect
Expand All @@ -54,14 +54,12 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/StirlingMarketingGroup/go-namecase v1.0.0 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/avast/retry-go/v4 v4.6.0 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
Expand Down Expand Up @@ -106,7 +104,7 @@ require (
github.com/emicklei/dot v1.6.2 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
Expand All @@ -132,7 +130,7 @@ require (
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.3 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
Expand Down Expand Up @@ -212,7 +210,7 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand Down Expand Up @@ -250,18 +248,18 @@ require (
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/api v0.196.0 // indirect
golang.org/x/tools v0.27.0 // indirect
google.golang.org/api v0.198.0 // indirect
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
Expand Down
Loading

0 comments on commit 1f00eba

Please sign in to comment.