forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: various improvements (cometbft#1603)
* docs: fix Query return parameters * docs: fix the number of ABCI connections ABCI creates 4 connections, not 3 * docs: bump cleveldb version 1.20 is 6 years old! 1.23 was released on Feb 24, 2021 * docs: remove check from PrepareProposal This check only confuses readers. PrepareProposal returns `proposal.Txs` (original list), not `txs`. Thus for loop is essentially noop and can be removed. Even if we modify PrepareProposal to return txs, it confuses application devs since CometBFT respects the limit when creating a proposal! Therefore, application devs should only check the limit when modifying the transactions, which is not the case here. * docs: minor highlighting * docs: fix syntax error missing comma * docs: fix [email protected]/proto/merge.go:123:28: type error go: go1.21.3 darwin/amd64 cometbft: v0.38.0 ``` ../../../go/pkg/mod/github.com/cosmos/[email protected]/proto/merge.go:123:28: type func(x *descriptorpb.FileDescriptorProto, y *descriptorpb.FileDescriptorProto) bool of func(x, y *descriptorpb.FileDescriptorProto) bool {…} does not match inferred type func(a *descriptorpb.FileDescriptorProto, b *descriptorpb.FileDescriptorProto) int for func(a E, b E) int ``` * docs: add missing double quote * docs: make the same changes in go guide - add a note about gogoproto - simplify PrepareProposal - add missing double quote * docs: remove XXX will create a separate PR updating gogoproto for v0.38 * Revert "docs: remove XXX" This reverts commit a4a1a04.
- Loading branch information
Showing
4 changed files
with
43 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,10 +101,18 @@ github.com/cometbft/cometbft v0.38.0 | |
) | ||
``` | ||
|
||
XXX: CometBFT `v0.38.0` uses a slightly outdated `gogoproto` library, which | ||
may fail to compile with newer Go versions. To avoid any compilation errors, | ||
upgrade `gogoproto` manually: | ||
|
||
```bash | ||
go get github.com/cosmos/[email protected] | ||
``` | ||
|
||
As you write the kvstore application, you can rebuild the binary by | ||
pulling any new dependencies and recompiling it. | ||
|
||
```sh | ||
```bash | ||
go get | ||
go build | ||
``` | ||
|
@@ -142,7 +150,7 @@ func (app *KVStoreApplication) Info(_ context.Context, info *abcitypes.RequestIn | |
} | ||
|
||
func (app *KVStoreApplication) Query(_ context.Context, req *abcitypes.RequestQuery) (*abcitypes.ResponseQuery, error) { | ||
return &abcitypes.ResponseQuery{} | ||
return &abcitypes.ResponseQuery{}, nil | ||
} | ||
|
||
func (app *KVStoreApplication) CheckTx(_ context.Context, check *abcitypes.RequestCheckTx) (*abcitypes.ResponseCheckTx, error) { | ||
|
@@ -457,30 +465,15 @@ The application is free to modify the group before returning from the call, as l | |
does not use more bytes than `RequestPrepareProposal.max_tx_bytes` | ||
For example, the application may reorder, add, or even remove transactions from the group to improve the | ||
execution of the block once accepted. | ||
|
||
In the following code, the application simply returns the unmodified group of transactions: | ||
|
||
```go | ||
func (app *KVStoreApplication) PrepareProposal(_ context.Context, proposal *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error) { | ||
totalBytes := int64(0) | ||
txs := make([]byte, 0) | ||
|
||
for _, tx := range proposal.Txs { | ||
totalBytes += int64(len(tx)) | ||
txs = append(txs, tx...) | ||
|
||
if totalBytes > int64(proposal.MaxTxBytes) { | ||
break | ||
} | ||
} | ||
|
||
return &abcitypes.ResponsePrepareProposal{Txs: proposal.Txs}, nil | ||
} | ||
func (app *KVStoreApplication) PrepareProposal(_ context.Context, proposal *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error) { | ||
return &abcitypes.ResponsePrepareProposal{Txs: proposal.Txs}, nil | ||
} | ||
``` | ||
|
||
This code snippet iterates through the proposed transactions and calculates the `total bytes`. If the `total bytes` exceeds the `MaxTxBytes` specified in the `RequestPrepareProposal` struct, the loop breaks and the transactions processed so far are returned. | ||
|
||
Note: It is the responsibility of the application to ensure that the `total bytes` of transactions returned does not exceed the `RequestPrepareProposal.max_tx_bytes` limit. | ||
|
||
Once a proposed block is received by a node, the proposal is passed to the application to give | ||
its blessing before voting to accept the proposal. | ||
|
||
|
@@ -497,7 +490,8 @@ func (app *KVStoreApplication) ProcessProposal(_ context.Context, proposal *abci | |
|
||
## 1.4 Starting an application and a CometBFT instance in the same process | ||
|
||
Now that we have the basic functionality of our application in place, let's put it all together inside of our main.go file. | ||
Now that we have the basic functionality of our application in place, let's put | ||
it all together inside of our `main.go` file. | ||
|
||
Change the contents of your `main.go` file to the following. | ||
|
||
|
@@ -588,7 +582,7 @@ func main() { | |
nm.DefaultGenesisDocProviderFunc(config), | ||
cfg.DefaultDBProvider, | ||
nm.DefaultMetricsProvider(config.Instrumentation), | ||
logger | ||
logger, | ||
) | ||
|
||
if err != nil { | ||
|
@@ -678,7 +672,7 @@ node, err := nm.NewNode( | |
nm.DefaultGenesisDocProviderFunc(config), | ||
cfg.DefaultDBProvider, | ||
nm.DefaultMetricsProvider(config.Instrumentation), | ||
logger) | ||
logger) | ||
|
||
if err != nil { | ||
log.Fatalf("Creating node: %v", err) | ||
|
@@ -795,7 +789,7 @@ The response contains a `base64` encoded representation of the data we submitted | |
To get the original value out of this data, we can use the `base64` command line utility: | ||
|
||
```bash | ||
echo cm9ja3M=" | base64 -d | ||
echo "cm9ja3M=" | base64 -d | ||
``` | ||
|
||
## Outro | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,10 +101,18 @@ github.com/cometbft/cometbft v0.38.0 | |
) | ||
``` | ||
|
||
XXX: CometBFT `v0.38.0` uses a slightly outdated `gogoproto` library, which | ||
may fail to compile with newer Go versions. To avoid any compilation errors, | ||
upgrade `gogoproto` manually: | ||
|
||
```bash | ||
go get github.com/cosmos/[email protected] | ||
``` | ||
|
||
As you write the kvstore application, you can rebuild the binary by | ||
pulling any new dependencies and recompiling it. | ||
|
||
```sh | ||
```bash | ||
go get | ||
go build | ||
``` | ||
|
@@ -449,34 +457,20 @@ included in blocks, it groups some of these transactions and then gives the appl | |
to modify the group by invoking `PrepareProposal`. | ||
|
||
The application is free to modify the group before returning from the call, as long as the resulting set | ||
does not use more bytes than `RequestPrepareProposal.max_tx_bytes' | ||
does not use more bytes than `RequestPrepareProposal.max_tx_bytes`. | ||
For example, the application may reorder, add, or even remove transactions from the group to improve the | ||
execution of the block once accepted. | ||
|
||
In the following code, the application simply returns the unmodified group of transactions: | ||
|
||
```go | ||
func (app *KVStoreApplication) PrepareProposal(_ context.Context, proposal *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error) { | ||
totalBytes := int64(0) | ||
txs := make([]byte, 0) | ||
|
||
for _, tx := range proposal.Txs { | ||
totalBytes += int64(len(tx)) | ||
txs = append(txs, tx...) | ||
|
||
if totalBytes > int64(proposal.MaxTxBytes) { | ||
break | ||
} | ||
} | ||
|
||
return &abcitypes.ResponsePrepareProposal{Txs: proposal.Txs}, nil | ||
} | ||
``` | ||
|
||
This code snippet iterates through the proposed transactions and calculates the `total bytes`. If the `total bytes` exceeds the `MaxTxBytes` specified in the `RequestPrepareProposal` struct, the loop breaks and the transactions processed so far are returned. | ||
|
||
Note: It is the responsibility of the application to ensure that the `total bytes` of transactions returned does not exceed the `RequestPrepareProposal.max_tx_bytes` limit. | ||
|
||
Once a proposed block is received by a node, the proposal is passed to the application to determine its validity before voting to accept the proposal. | ||
Once a proposed block is received by a node, the proposal is passed to the | ||
application to determine its validity before voting to accept the proposal. | ||
|
||
This mechanism may be used for different reasons, for example to deal with blocks manipulated | ||
by malicious nodes, in which case the block should not be considered valid. | ||
|
@@ -491,7 +485,8 @@ func (app *KVStoreApplication) ProcessProposal(_ context.Context, proposal *abci | |
|
||
## 1.4 Starting an application and a CometBFT instance | ||
|
||
Now that we have the basic functionality of our application in place, let's put it all together inside of our `main.go` file. | ||
Now that we have the basic functionality of our application in place, let's put | ||
it all together inside of our `main.go` file. | ||
|
||
Change the contents of your `main.go` file to the following. | ||
|
||
|
@@ -706,7 +701,7 @@ The response contains a `base64` encoded representation of the data we submitted | |
To get the original value out of this data, we can use the `base64` command line utility: | ||
|
||
```bash | ||
echo cm9ja3M=" | base64 -d | ||
echo "cm9ja3M=" | base64 -d | ||
``` | ||
|
||
## Outro | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters