Skip to content

Commit

Permalink
fix: smart contract deployment error (#1261)
Browse files Browse the repository at this point in the history
# Testing completed

- [x] test coverage exists or has been added/updated
- [x] tested in a private testnet

# Breaking changes

- [x] I have checked my code for breaking changes
- [x] If there are breaking changes, there is a supporting migration.

---------

Co-authored-by: Luis Carvalho <[email protected]>
  • Loading branch information
byte-bandit and maharifu committed Aug 16, 2024
1 parent 28c5684 commit 23886d7
Show file tree
Hide file tree
Showing 34 changed files with 569 additions and 298 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func New(
app.GetSubspace(consensusmoduletypes.ModuleName),
app.ValsetKeeper,
consensusRegistry,
(&app.TreasuryKeeper).GetCombinedFeesForRelay,
&app.TreasuryKeeper,
)

app.EvmKeeper = *evmmodulekeeper.NewKeeper(
Expand Down
12 changes: 10 additions & 2 deletions proto/palomachain/paloma/consensus/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ service Query {

// Queries one message by ID.
rpc MessageByID(QueryMessageByIDRequest)
returns (MessageWithSignatures) {
returns (MessageQueryResult) {
option (google.api.http).get =
"/palomachain/paloma/consensus/{queueTypeName}/message/{id}";
}
Expand Down Expand Up @@ -102,18 +102,26 @@ message ValidatorSignature {
}

message MessageWithSignatures {
reserved 8;
reserved "evidence";

bytes nonce = 1;
uint64 id = 2;
google.protobuf.Any msg = 3;
repeated ValidatorSignature signData = 4;
bytes bytesToSign = 5;
bytes publicAccessData = 6;
bytes errorData = 7;
repeated Evidence evidence = 8;
uint64 valsetID = 9;
uint64 gasEstimate = 10;
}

message MessageQueryResult {
MessageWithSignatures message = 1;
repeated Evidence evidence = 2;
repeated GasEstimate gasEstimates = 3;
}

message QueryMessageByIDRequest {
string queueTypeName = 1;
uint64 id = 2;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/evm/keeper/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func initFixture(t ginkgo.FullGinkgoTInterface) *fixture {
helper.GetSubspace(consensusmoduletypes.ModuleName, paramsKeeper),
valsetKeeper,
consensusRegistry,
(&tk).GetCombinedFeesForRelay,
&tk,
)

var evmKeeper *evmmodulekeeper.Keeper = &evmmodulekeeper.Keeper{}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/paloma/keeper/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func initFixture(t ginkgo.FullGinkgoTInterface) *fixture {
helper.GetSubspace(consensusmoduletypes.ModuleName, paramsKeeper),
valsetKeeper,
consensusRegistry,
(&tk).GetCombinedFeesForRelay,
&tk,
)

var evmKeeper *evmmodulekeeper.Keeper = &evmmodulekeeper.Keeper{}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/scheduler/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func initFixture(t ginkgo.FullGinkgoTInterface) *fixture {
helper.GetSubspace(consensusmoduletypes.ModuleName, paramsKeeper),
valsetKeeper,
consensusRegistry,
(&tk).GetCombinedFeesForRelay,
&tk,
)

var evmKeeper *evmmodulekeeper.Keeper = &evmmodulekeeper.Keeper{}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/valset/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func initFixture(t ginkgo.FullGinkgoTInterface) *fixture {
helper.GetSubspace(consensusmoduletypes.ModuleName, paramsKeeper),
valsetKeeper,
consensusRegistry,
(&tk).GetCombinedFeesForRelay,
&tk,
)

var evmKeeper *evmmodulekeeper.Keeper = &evmmodulekeeper.Keeper{}
Expand Down
23 changes: 4 additions & 19 deletions util/libcons/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,42 +207,27 @@ func (c ConsensusChecker) VerifyGasEstimates(ctx context.Context, p liblog.LogPr
var cp consensusPower
cp.setTotal(snapshot.TotalShares)

values := make(map[uint64]int, len(estimates))
for _, v := range estimates {
val, found := snapshot.GetValidator(v.GetValAddress())
if !found {
continue
}
cp.add(val.ShareCount)
values[v.GetValue()]++
}

result.totalFromConsensus(cp)
if !cp.consensus() {
return 0, ErrConsensusNotAchieved
}

// Identify esimate with more than 1 validator agreeing on the vote
validEstimates := make([]uint64, 0, len(estimates))
for k, v := range values {
if v < 2 {
// We need at least 2 validators to agree on the same gas estimate
// in order to include it in the calculation.
logger.WithFields("value", k).Debug("Rejecting value with less than 2 votes.")
continue
}

logger.WithFields("value", k, "voters", v).Debug("Including value in the calculation.")
validEstimates = append(validEstimates, k)
}

if len(validEstimates) < 1 {
return 0, fmt.Errorf("no gas estimate has been agreed upon")
estimateValues := make([]uint64, len(estimates))
for i := range estimates {
estimateValues[i] = estimates[i].GetValue()
}

// Retrieve the median value of the gas estimates and
// multiply value by 1.2 to allow for some security margin
winner := palomath.Median(validEstimates)
winner := palomath.Median(estimateValues)
logger.WithFields("gas-estimate", winner).Debug("Built median value of gas estimates.")

if winner == 0 {
Expand Down
2 changes: 0 additions & 2 deletions x/consensus/keeper/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestDeleteOldMessages(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(msgType),
consensus.WithBytesToSignCalc(msgType.ConsensusSignBytes()),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down Expand Up @@ -111,7 +110,6 @@ func TestGetMessagesOlderThan(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(msgType),
consensus.WithBytesToSignCalc(msgType.ConsensusSignBytes()),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down
8 changes: 7 additions & 1 deletion x/consensus/keeper/concensus_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ func (k Keeper) GetMessagesForGasEstimation(ctx context.Context, queueTypeName s
return nil, err
}

// Check for existing valset update messages on any target chains
valsetUpdatesOnChain, err := k.GetPendingValsetUpdates(ctx, queueTypeName)
if err != nil {
return nil, err
}

msgs = slice.Filter(msgs, func(msg types.QueuedSignedMessageI) bool {
// Filter out messages which don't require gas estimation
if !msg.GetRequireGasEstimation() {
Expand All @@ -141,7 +147,7 @@ func (k Keeper) GetMessagesForGasEstimation(ctx context.Context, queueTypeName s
}
}

return true
return filters.IsNotBlockedByValset(valsetUpdatesOnChain, msg)
})

if len(msgs) > defaultResponseMessageCount {
Expand Down
10 changes: 0 additions & 10 deletions x/consensus/keeper/concensus_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestEndToEndTestingOfPuttingAndGettingMessagesOfTheConsensusQueue(t *testin
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(msgType),
consensus.WithBytesToSignCalc(msgType.ConsensusSignBytes()),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down Expand Up @@ -103,7 +102,6 @@ func TestJailValidatorsWhichMissedAttestation(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(msgType),
consensus.WithBytesToSignCalc(msgType.ConsensusSignBytes()),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down Expand Up @@ -387,7 +385,6 @@ func TestGetMessagesFromQueue(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(msgType),
consensus.WithBytesToSignCalc(msgType.ConsensusSignBytes()),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down Expand Up @@ -422,7 +419,6 @@ func TestGetMessagesForRelaying(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(uvType),
consensus.WithBytesToSignCalc(func(msg types.ConsensusMsg, salt types.Salt) []byte { return []byte{} }),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand All @@ -433,7 +429,6 @@ func TestGetMessagesForRelaying(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queueWithValsetUpdatesPending),
consensus.WithStaticTypeCheck(uvType),
consensus.WithBytesToSignCalc(func(msg types.ConsensusMsg, salt types.Salt) []byte { return []byte{} }),
consensus.WithChainInfo(chainType, "pending-chain"),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down Expand Up @@ -926,9 +921,6 @@ func TestGettingMessagesThatHaveReachedConsensus(t *testing.T) {
consensus.WithStaticTypeCheck(&types.SimpleMessage{}),
consensus.WithQueueTypeName(defaultQueueName),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithBytesToSignCalc(func(msg types.ConsensusMsg, salt types.Salt) []byte {
return []byte("sign-me")
}),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
}),
Expand Down Expand Up @@ -967,7 +959,6 @@ func TestAddingSignatures(t *testing.T) {
consensus.WithAttestator(mck),
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(msgType),
consensus.WithBytesToSignCalc(msgType.ConsensusSignBytes()),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func(msg []byte, sig []byte, pk []byte) bool {
p := secp256k1.PubKey(pk)
Expand Down Expand Up @@ -1070,7 +1061,6 @@ func TestGetMessagesForEstimating(t *testing.T) {
opt: consensus.ApplyOpts(nil,
consensus.WithQueueTypeName(queue),
consensus.WithStaticTypeCheck(uvType),
consensus.WithBytesToSignCalc(func(msg types.ConsensusMsg, salt types.Salt) []byte { return []byte{} }),
consensus.WithChainInfo(chainType, chainReferenceID),
consensus.WithVerifySignature(func([]byte, []byte, []byte) bool {
return true
Expand Down
3 changes: 0 additions & 3 deletions x/consensus/keeper/consensus/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ func TestBatching(t *testing.T) {
Ider: keeperutil.NewIDGenerator(sg, nil),
Cdc: types.ModuleCdc,
TypeCheck: types.StaticTypeChecker(msgType),
BytesToSignCalculator: types.TypedBytesToSign(func(msgs *types.Batch, _ types.Salt) []byte {
return []byte("hello")
}),
VerifySignature: func([]byte, []byte, []byte) bool {
return true
},
Expand Down
42 changes: 17 additions & 25 deletions x/consensus/keeper/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ type Queue struct {
}

type QueueOptions struct {
Batched bool
QueueTypeName string
Sg keeperutil.StoreGetter
Ider keeperutil.IDGenerator
Cdc codec.Codec
TypeCheck types.TypeChecker
BytesToSignCalculator types.BytesToSignFunc
VerifySignature types.VerifySignatureFunc
ChainType types.ChainType
Attestator types.Attestator
ChainReferenceID string
Batched bool
QueueTypeName string
Sg keeperutil.StoreGetter
Ider keeperutil.IDGenerator
Cdc codec.Codec
TypeCheck types.TypeChecker
VerifySignature types.VerifySignatureFunc
ChainType types.ChainType
Attestator types.Attestator
ChainReferenceID string
}

type OptFnc func(*QueueOptions)
Expand All @@ -56,12 +55,6 @@ func WithStaticTypeCheck(val any) OptFnc {
}
}

func WithBytesToSignCalc(val types.BytesToSignFunc) OptFnc {
return func(opt *QueueOptions) {
opt.BytesToSignCalculator = val
}
}

func WithVerifySignature(val types.VerifySignatureFunc) OptFnc {
return func(opt *QueueOptions) {
opt.VerifySignature = val
Expand Down Expand Up @@ -102,10 +95,6 @@ func NewQueue(qo QueueOptions) (Queue, error) {
return Queue{}, ErrNilTypeCheck
}

if qo.BytesToSignCalculator == nil {
return Queue{}, ErrNilBytesToSignCalculator
}

if qo.VerifySignature == nil {
return Queue{}, ErrNilVerifySignature
}
Expand Down Expand Up @@ -139,9 +128,11 @@ func (c Queue) Put(ctx context.Context, msg ConsensusMsg, opts *PutOptions) (uin
requireSignatures = opts.RequireSignatures
requireGasEstimation = opts.RequireGasEstimation
mid = opts.MsgIDToReplace
publicAccessData = &types.PublicAccessData{
ValAddress: nil,
Data: opts.PublicAccessData,
if len(opts.PublicAccessData) > 0 {
publicAccessData = &types.PublicAccessData{
ValAddress: nil,
Data: opts.PublicAccessData,
}
}
}

Expand All @@ -160,7 +151,8 @@ func (c Queue) Put(ctx context.Context, msg ConsensusMsg, opts *PutOptions) (uin
if err != nil {
return 0, fmt.Errorf("failed to get message by id: %w", err)
}
m, ok := qsmi.(*types.QueuedSignedMessage)
var ok bool
m, ok = qsmi.(*types.QueuedSignedMessage)
if !ok {
return 0, fmt.Errorf("failed to cast to queued signed message")
}
Expand Down
13 changes: 6 additions & 7 deletions x/consensus/keeper/consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ func TestConsensusQueueAllMethods(t *testing.T) {
mck.On("ValidateEvidence", mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
cq := Queue{
qo: QueueOptions{
QueueTypeName: "simple-message",
Sg: sg,
Ider: keeperutil.NewIDGenerator(sg, nil),
Cdc: types.ModuleCdc,
TypeCheck: types.StaticTypeChecker(msgType),
Attestator: mck,
BytesToSignCalculator: msgType.ConsensusSignBytes(),
QueueTypeName: "simple-message",
Sg: sg,
Ider: keeperutil.NewIDGenerator(sg, nil),
Cdc: types.ModuleCdc,
TypeCheck: types.StaticTypeChecker(msgType),
Attestator: mck,
VerifySignature: func([]byte, []byte, []byte) bool {
return true
},
Expand Down
Loading

0 comments on commit 23886d7

Please sign in to comment.