Skip to content

Commit

Permalink
Receive necessary information in x/compute/module BeginBlock correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
iKapitonau committed Jul 29, 2024
1 parent 62f9acf commit dc6bcc2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 82 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.21

replace (
cosmossdk.io/store => github.com/scrtlabs/cosmos-sdk-store v0.0.0-20240709111432-a66f64b2f1d4
github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.0-dev.0.20240716092925-e358458fc927
github.com/cosmos/cosmos-sdk => github.com/scrtlabs/cosmos-sdk v0.46.0-beta2.0.20240716091438-a02a17a7d506
github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.0-dev.0.20240729151849-eb53eeaca72d
github.com/cosmos/cosmos-sdk => github.com/scrtlabs/cosmos-sdk v0.46.0-beta2.0.20240729203810-30cef60e4b1e
github.com/cosmos/iavl => github.com/scrtlabs/iavl v1.0.0-alpha.1.0.20240710081403-73fd37d68158
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,14 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
github.com/scrtlabs/cosmos-sdk v0.46.0-beta2.0.20240716091438-a02a17a7d506 h1:vRthd7VlmITpIP5PC5Jc0A1RMQZIX5+AQ4ERUeW1edE=
github.com/scrtlabs/cosmos-sdk v0.46.0-beta2.0.20240716091438-a02a17a7d506/go.mod h1:Zb+DgHtiByNwgj71IlJBXwOq6dLhtyAq3AgqpXm/jHo=
github.com/scrtlabs/cosmos-sdk v0.46.0-beta2.0.20240729203810-30cef60e4b1e h1:jriAv+sKRGGS9qHebX8uyqRalVXX3zaFvNnURT6Lc0M=
github.com/scrtlabs/cosmos-sdk v0.46.0-beta2.0.20240729203810-30cef60e4b1e/go.mod h1:Zb+DgHtiByNwgj71IlJBXwOq6dLhtyAq3AgqpXm/jHo=
github.com/scrtlabs/cosmos-sdk-store v0.0.0-20240709111432-a66f64b2f1d4 h1:fI9xbKD4G+g8sfpLOXzqmKZVOAkfJ1e02NQQdsZHdIU=
github.com/scrtlabs/cosmos-sdk-store v0.0.0-20240709111432-a66f64b2f1d4/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
github.com/scrtlabs/iavl v1.0.0-alpha.1.0.20240710081403-73fd37d68158 h1:RbXix8d/6evD4jlatRruNT+LBpadK3eeIzyqNrZ/UZE=
github.com/scrtlabs/iavl v1.0.0-alpha.1.0.20240710081403-73fd37d68158/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
github.com/scrtlabs/tendermint v0.38.0-dev.0.20240716092925-e358458fc927 h1:SxTlPqmaOpqayfjB9ZFQZ71a8iQcubeVoDR/ksjEJbM=
github.com/scrtlabs/tendermint v0.38.0-dev.0.20240716092925-e358458fc927/go.mod h1:zHOzayCqcjMdAeogq7MU8xPrSEoU8gzPDrfx8/ReCT8=
github.com/scrtlabs/tendermint v0.38.0-dev.0.20240729151849-eb53eeaca72d h1:3iQifSXVR+w38fbZcQysQJFohRa9NTJzjFNSfz+v3mw=
github.com/scrtlabs/tendermint v0.38.0-dev.0.20240729151849-eb53eeaca72d/go.mod h1:zHOzayCqcjMdAeogq7MU8xPrSEoU8gzPDrfx8/ReCT8=
github.com/scrtlabs/tm-secret-enclave v1.11.3 h1:3WVDS4x11tidRvCK/FbemtuVDMgujvSzMSt9sKLaMwY=
github.com/scrtlabs/tm-secret-enclave v1.11.3/go.mod h1:nxZQtzzAqBNBLOEXSv4cKlUnVA4vRmHOn6ujr3kxVME=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
Expand Down
108 changes: 51 additions & 57 deletions third_party/proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ service ABCI {
rpc InitChain(RequestInitChain) returns (ResponseInitChain);
rpc ListSnapshots(RequestListSnapshots) returns (ResponseListSnapshots);
rpc OfferSnapshot(RequestOfferSnapshot) returns (ResponseOfferSnapshot);
rpc LoadSnapshotChunk(RequestLoadSnapshotChunk)
returns (ResponseLoadSnapshotChunk);
rpc ApplySnapshotChunk(RequestApplySnapshotChunk)
returns (ResponseApplySnapshotChunk);
rpc LoadSnapshotChunk(RequestLoadSnapshotChunk) returns (ResponseLoadSnapshotChunk);
rpc ApplySnapshotChunk(RequestApplySnapshotChunk) returns (ResponseApplySnapshotChunk);
rpc PrepareProposal(RequestPrepareProposal) returns (ResponsePrepareProposal);
rpc ProcessProposal(RequestProcessProposal) returns (ResponseProcessProposal);
rpc ExtendVote(RequestExtendVote) returns (ResponseExtendVote);
Expand Down Expand Up @@ -59,7 +57,7 @@ message Request {
RequestVerifyVoteExtension verify_vote_extension = 19;
RequestFinalizeBlock finalize_block = 20;
}
reserved 4, 7, 9, 10; // SetOption, BeginBlock, DeliverTx, EndBlock
reserved 4, 7, 9, 10; // SetOption, BeginBlock, DeliverTx, EndBlock
}

message RequestEcho {
Expand All @@ -76,8 +74,7 @@ message RequestInfo {
}

message RequestInitChain {
google.protobuf.Timestamp time = 1
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
google.protobuf.Timestamp time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
string chain_id = 2;
tendermint.types.ConsensusParams consensus_params = 3;
repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false];
Expand Down Expand Up @@ -109,8 +106,8 @@ message RequestListSnapshots {}

// offers a snapshot to the application
message RequestOfferSnapshot {
Snapshot snapshot = 1; // snapshot offered by peers
bytes app_hash = 2; // light client-verified app hash for snapshot height
Snapshot snapshot = 1; // snapshot offered by peers
bytes app_hash = 2; // light client-verified app hash for snapshot height
}

// loads a snapshot chunk
Expand Down Expand Up @@ -174,7 +171,7 @@ message RequestExtendVote {
// Verify the vote extension
message RequestVerifyVoteExtension {
// the hash of the block that this received vote corresponds to
bytes hash = 1;
bytes hash = 1;
// the validator that signed the vote extension
bytes validator_address = 2;
int64 height = 3;
Expand All @@ -191,8 +188,10 @@ message RequestFinalizeBlock {
google.protobuf.Timestamp time = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
bytes next_validators_hash = 7;
// proposer_address is the address of the public key of the original proposer of the block.
bytes proposer_address = 8;
tendermint.types.EncryptedRandom encrypted_random = 9; // a random number encrypted by the proposer to be used in contracts
bytes proposer_address = 8;
tendermint.types.EncryptedRandom encrypted_random =
9; // a random number encrypted by the proposer to be used in contracts
tendermint.types.Commit commit = 10;
}

//----------------------------------------
Expand All @@ -218,7 +217,7 @@ message Response {
ResponseVerifyVoteExtension verify_vote_extension = 20;
ResponseFinalizeBlock finalize_block = 21;
}
reserved 5, 8, 10, 11; // SetOption, BeginBlock, DeliverTx, EndBlock
reserved 5, 8, 10, 11; // SetOption, BeginBlock, DeliverTx, EndBlock
}

// nondeterministic
Expand Down Expand Up @@ -251,8 +250,8 @@ message ResponseInitChain {
message ResponseQuery {
uint32 code = 1;
// bytes data = 2; // use "value" instead.
string log = 3; // nondeterministic
string info = 4; // nondeterministic
string log = 3; // nondeterministic
string info = 4; // nondeterministic
int64 index = 5;
bytes key = 6;
bytes value = 7;
Expand All @@ -264,13 +263,12 @@ message ResponseQuery {
message ResponseCheckTx {
uint32 code = 1;
bytes data = 2;
string log = 3; // nondeterministic
string info = 4; // nondeterministic
string log = 3; // nondeterministic
string info = 4; // nondeterministic
int64 gas_wanted = 5 [json_name = "gas_wanted"];
int64 gas_used = 6 [json_name = "gas_used"];
repeated Event events = 7
[(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
string codespace = 8;
repeated Event events = 7 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
string codespace = 8;

// These reserved fields were used until v0.37 by the priority mempool (now
// removed).
Expand All @@ -279,7 +277,7 @@ message ResponseCheckTx {
}

message ResponseCommit {
reserved 1, 2; // data was previously returned here
reserved 1, 2; // data was previously returned here
int64 retain_height = 3;
}

Expand All @@ -291,12 +289,12 @@ message ResponseOfferSnapshot {
Result result = 1;

enum Result {
UNKNOWN = 0; // Unknown result, abort all snapshot restoration
ACCEPT = 1; // Snapshot accepted, apply chunks
ABORT = 2; // Abort all snapshot restoration
REJECT = 3; // Reject this specific snapshot, try others
REJECT_FORMAT = 4; // Reject all snapshots of this format, try others
REJECT_SENDER = 5; // Reject all snapshots from the sender(s), try others
UNKNOWN = 0; // Unknown result, abort all snapshot restoration
ACCEPT = 1; // Snapshot accepted, apply chunks
ABORT = 2; // Abort all snapshot restoration
REJECT = 3; // Reject this specific snapshot, try others
REJECT_FORMAT = 4; // Reject all snapshots of this format, try others
REJECT_SENDER = 5; // Reject all snapshots from the sender(s), try others
}
}

Expand All @@ -306,16 +304,16 @@ message ResponseLoadSnapshotChunk {

message ResponseApplySnapshotChunk {
Result result = 1;
repeated uint32 refetch_chunks = 2; // Chunks to refetch and reapply
repeated string reject_senders = 3; // Chunk senders to reject and ban
repeated uint32 refetch_chunks = 2; // Chunks to refetch and reapply
repeated string reject_senders = 3; // Chunk senders to reject and ban

enum Result {
UNKNOWN = 0; // Unknown result, abort all snapshot restoration
ACCEPT = 1; // Chunk successfully accepted
ABORT = 2; // Abort all snapshot restoration
RETRY = 3; // Retry chunk (combine with refetch and reject)
RETRY_SNAPSHOT = 4; // Retry snapshot (combine with refetch and reject)
REJECT_SNAPSHOT = 5; // Reject this snapshot, try others
UNKNOWN = 0; // Unknown result, abort all snapshot restoration
ACCEPT = 1; // Chunk successfully accepted
ABORT = 2; // Abort all snapshot restoration
RETRY = 3; // Retry chunk (combine with refetch and reject)
RETRY_SNAPSHOT = 4; // Retry snapshot (combine with refetch and reject)
REJECT_SNAPSHOT = 5; // Reject this snapshot, try others
}
}

Expand Down Expand Up @@ -347,14 +345,13 @@ message ResponseVerifyVoteExtension {
// Incorrectly implementing this thus has liveness implications as it may affect
// CometBFT's ability to receive 2/3+ valid votes to finalize the block.
// Honest nodes should never be rejected.
REJECT = 2;
REJECT = 2;
}
}

message ResponseFinalizeBlock {
// set of block events emmitted as part of executing the block
repeated Event events = 1
[(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
repeated Event events = 1 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
// the result of executing each transaction including the events
// the particular transction emitted. This should match the order
// of the transactions delivered in the block itself
Expand All @@ -363,7 +360,8 @@ message ResponseFinalizeBlock {
repeated ValidatorUpdate validator_updates = 3 [(gogoproto.nullable) = false];
// updates to the consensus params, if any.
tendermint.types.ConsensusParams consensus_param_updates = 4;
// app_hash is the hash of the applications' state which is used to confirm that execution of the transactions was deterministic. It is up to the application to decide which algorithm to use.
// app_hash is the hash of the applications' state which is used to confirm that execution of the transactions was
// deterministic. It is up to the application to decide which algorithm to use.
bytes app_hash = 5;
}

Expand Down Expand Up @@ -391,17 +389,14 @@ message ExtendedCommitInfo {
// Later, transactions may be queried using these events.
message Event {
string type = 1;
repeated EventAttribute attributes = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "attributes,omitempty"
];
repeated EventAttribute attributes = 2 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "attributes,omitempty"];
}

// EventAttribute is a single key-value pair, associated with an event.
message EventAttribute {
string key = 1;
string value = 2;
bool index = 3; // nondeterministic
bool index = 3; // nondeterministic
}

// ExecTxResult contains results of executing one individual transaction.
Expand All @@ -410,12 +405,12 @@ message EventAttribute {
message ExecTxResult {
uint32 code = 1;
bytes data = 2;
string log = 3; // nondeterministic
string info = 4; // nondeterministic
string log = 3; // nondeterministic
string info = 4; // nondeterministic
int64 gas_wanted = 5 [json_name = "gas_wanted"];
int64 gas_used = 6 [json_name = "gas_used"];
repeated Event events = 7
[(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; // nondeterministic
[(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; // nondeterministic
string codespace = 8;
}

Expand All @@ -433,9 +428,9 @@ message TxResult {
// Blockchain Types

message Validator {
bytes address = 1; // The first 20 bytes of SHA256(public key)
bytes address = 1; // The first 20 bytes of SHA256(public key)
// PubKey pub_key = 2 [(gogoproto.nullable)=false];
int64 power = 3; // The voting power
int64 power = 3; // The voting power
}

message ValidatorUpdate {
Expand All @@ -444,7 +439,7 @@ message ValidatorUpdate {
}

message VoteInfo {
Validator validator = 1 [(gogoproto.nullable) = false];
Validator validator = 1 [(gogoproto.nullable) = false];
tendermint.types.BlockIDFlag block_id_flag = 3;

reserved 2; // signed_last_block
Expand Down Expand Up @@ -476,8 +471,7 @@ message Misbehavior {
// The height when the offense occurred
int64 height = 3;
// The corresponding time where the offense occurred
google.protobuf.Timestamp time = 4
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// Total voting power of the validator set in case the ABCI application does
// not store historical validators.
// https://github.com/tendermint/tendermint/issues/4581
Expand All @@ -488,9 +482,9 @@ message Misbehavior {
// State Sync Types

message Snapshot {
uint64 height = 1; // The height at which the snapshot was taken
uint32 format = 2; // The application-specific snapshot format
uint32 chunks = 3; // Number of chunks in the snapshot
bytes hash = 4; // Arbitrary snapshot hash, equal only if identical
bytes metadata = 5; // Arbitrary application metadata
uint64 height = 1; // The height at which the snapshot was taken
uint32 format = 2; // The application-specific snapshot format
uint32 chunks = 3; // Number of chunks in the snapshot
bytes hash = 4; // Arbitrary snapshot hash, equal only if identical
bytes metadata = 5; // Arbitrary application metadata
}
22 changes: 3 additions & 19 deletions x/compute/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,15 @@ func (am AppModule) BeginBlock(c context.Context) error {
ctx.Logger().Error("Failed to marshal block header")
return err
}
commit := ctx.CometInfo().GetLastCommit()
voteInfos := commit.Votes()
var commitSigs []tm_type.CommitSig
for i := 0; i < voteInfos.Len(); i++ {
voteInfo := voteInfos.Get(i)
commitSigs = append(commitSigs, tm_type.CommitSig{
BlockIdFlag: tm_type.BlockIDFlag(voteInfo.GetBlockIDFlag()),
ValidatorAddress: voteInfo.Validator().Address(),
})
}

tm_commit := tm_type.Commit{
Height: ctx.BlockHeight(),
Round: commit.Round(),
BlockID: block_header.LastBlockId,
Signatures: commitSigs,
}

b_commit, err := tm_commit.Marshal()
commit := ctx.Commit()
b_commit, err := commit.Marshal()
if err != nil {
ctx.Logger().Error("Failed to marshal commit")
return err
}

x2_data := scrt.UnFlatten(ctx.TxBytes())
x2_data := scrt.UnFlatten(ctx.TxBytes())
tm_data := tm_type.Data{Txs: x2_data}
data, err := tm_data.Marshal()
if err != nil {
Expand Down

0 comments on commit dc6bcc2

Please sign in to comment.