-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: ABCI 1.0 baseapp integration #13453
Changes from 130 commits
d72d1a2
01ed963
35ff6d6
bbd9405
3cc3fb1
9ffa994
aa103ef
77a9b37
46c34ff
9a4eeac
09f4e6b
a6fb1e5
c8931c9
c3746c7
816dc70
85c5f1e
a10b047
59b2195
aafb4ce
1798d68
6be3812
5f2b9cc
14afa8d
ee97a25
bfda138
ee2ed7e
afc04eb
a9a8fa3
9556eff
87bf3b6
5b647eb
6407c12
629d17b
0bd11ff
01858d2
ed23ead
fc784dc
1758aae
0ec9335
1520b5d
fa7cc9a
c4495fd
f4ff6c6
f57847d
82f701c
16100f9
582e914
a8d58dd
1e1be0e
b749c6f
26eb530
5143d58
90996c7
5be329f
c25385a
1725e8d
7cf3a52
9c44433
15834d7
7457271
b0b8b27
5eac4b7
834f85f
d90ac72
fbe1bb4
ffe535d
056bca1
78b774c
192d421
7adc7bf
bd1b55f
96cd0c7
83dcbc7
e473bcf
613019a
3099039
295703f
47fad32
302f81e
83d6320
873cb74
5849815
e61ceea
48ce41c
c24a152
ad829d4
8d13cc2
869b524
47ba2c2
541f112
bae75b9
af4f5bc
1d5b1d4
de40135
6c15d92
250ea90
5be06eb
2663dc2
c2e7069
42d52c1
4ecf2e2
58bd2ce
00a7a8f
be180e8
9d120c1
4f466a4
abbe016
d2f8b21
63d6606
91e30d7
ea8589d
d02e4a9
7d2fd41
1683445
b9a2e05
a1f2ae0
5bd05f8
0c37d23
19e6e3e
5cc97f4
2bc00a1
e42d6a8
1366a87
f2457fa
d7dc83a
bfee335
b7fe34c
52e10e6
4e429dd
5c80aaf
46fb8c4
a17f506
078168b
59cc71f
e321ec2
db1f4cd
ba57a58
227ea17
522aaab
7021bdd
81c67f7
af919d3
54837e8
e9a7232
f634306
6034696
fb6eb64
838e126
c043a7a
b07a56c
45044bd
5ccf004
0528e05
1cb53a0
cc608b6
2f56b6d
bab393a
b88614e
2afe7b1
1dfe713
5fbee38
94ddfa2
f6c073f
179869e
b1c84cb
e514f7b
c834047
4d11de2
4d295b1
46ebfc4
ffdb934
55d13d7
3f76cb6
cb147a3
b04e051
6f71213
0cc1aaa
732d1b1
6601cf3
96cb90b
657ce24
736306c
e907d77
61bd98a
1f53170
369c622
7a7504a
32899a5
ddec83e
3e6e1a4
9c23184
3f1dcd8
d4234d8
580c8b3
3c8640e
d1a1cf8
0697e88
fc4bccb
659faa3
10cd747
bfe7faf
de876ca
51e0da9
7dc0684
72a5c3c
201d52e
dea715f
0af1899
3134207
9e3048f
41816be
678b555
a75e4ef
215d2a6
587f0fb
88f574d
7180e94
97a9c76
6e5ff1c
e1d5ed4
8d4e97b
99566ce
16e98c9
a15d9f0
cf88b04
5db4724
0696b82
a8dd44d
ef5a625
3ac1d30
deb33f5
74775b6
1e36da8
a3bc195
ccc00f1
5595988
26641b6
061e68e
e646e46
e594b59
40a5b21
e50ef7d
5ce1d3a
97f02e9
c10e857
323b9f7
3575579
348f67e
4576305
61e1b60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,13 @@ import ( | |
"syscall" | ||
"time" | ||
|
||
"github.com/cosmos/gogoproto/proto" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
"google.golang.org/grpc/codes" | ||
grpcstatus "google.golang.org/grpc/status" | ||
|
||
"github.com/cosmos/gogoproto/proto" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
|
@@ -249,8 +250,19 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc | |
// Ref: https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-060-abci-1.0.md | ||
// Ref: https://github.com/tendermint/tendermint/blob/main/spec/abci/abci%2B%2B_basic_concepts.md | ||
func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal { | ||
// TODO: Implement. | ||
return abci.ResponsePrepareProposal{Txs: req.Txs} | ||
memTxs, selectErr := app.mempool.Select(req.Txs, req.MaxTxBytes) | ||
if selectErr != nil { | ||
panic(selectErr) | ||
} | ||
var txs [][]byte | ||
for _, memTx := range memTxs { | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bz, encErr := app.txEncoder(memTx) | ||
if encErr != nil { | ||
panic(encErr) | ||
} | ||
txs = append(txs, bz) | ||
} | ||
return abci.ResponsePrepareProposal{Txs: txs} | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// ProcessProposal implements the ProcessProposal ABCI method and returns a | ||
|
@@ -266,7 +278,19 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) abci.Respon | |
// Ref: https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-060-abci-1.0.md | ||
// Ref: https://github.com/tendermint/tendermint/blob/main/spec/abci/abci%2B%2B_basic_concepts.md | ||
func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) abci.ResponseProcessProposal { | ||
// TODO: Implement. | ||
ctx := app.checkState.ctx | ||
|
||
for _, txBytes := range req.Txs { | ||
anteCtx, _ := app.cacheTxContext(ctx, txBytes) | ||
tx, err := app.txDecoder(txBytes) | ||
if err != nil { | ||
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reject looks right to me, as a TX that fails to decode is a sign that the encoder was buggy, independently of the actual App state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree. If we cannot decode a tx, that indicates some malicious behavior by the proposer in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failure to decode a tx, or any other error encountered when parsing/validating incoming data, doesn't automatically indicate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexanderbez For the moment, Tendermint will prevent that (malformed) proposal from being decided by prevoting To your second question, you can and should return reject in this case |
||
} | ||
ctx, err = app.anteHandler(anteCtx, tx, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you not running this on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JeancarloBarrios this doesn't look quite correct. In the ADR, we allude to the app having full control over @sergio-mena for the record, we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I have updated this i still need to push but I updated after our conversation yesterday There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexanderbez be careful here folks. Let me describe an example and you tell me if that can happen.
Can this happen? |
||
if err != nil { | ||
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT} | ||
} | ||
} | ||
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package baseapp | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
@@ -20,6 +21,7 @@ import ( | |
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/types/mempool" | ||
) | ||
|
||
const ( | ||
|
@@ -55,8 +57,9 @@ type BaseApp struct { //nolint: maligned | |
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages | ||
interfaceRegistry codectypes.InterfaceRegistry | ||
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx | ||
txEncoder sdk.TxEncoder // marshal sdk.Tx into []byte | ||
|
||
mempool sdk.Mempool // application side mempool | ||
mempool mempool.Mempool // application side mempool | ||
anteHandler sdk.AnteHandler // ante handler for fee and auth | ||
postHandler sdk.AnteHandler // post handler, optional, e.g. for tips | ||
initChainer sdk.InitChainer // initialize state with validators and state blob | ||
|
@@ -160,6 +163,11 @@ func NewBaseApp( | |
option(app) | ||
} | ||
|
||
// if execution of options has left certain required fields nil, let's set them to default values | ||
if app.mempool == nil { | ||
app.mempool = mempool.DefaultPriorityMempool() | ||
} | ||
|
||
if app.interBlockCache != nil { | ||
app.cms.SetInterBlockCache(app.interBlockCache) | ||
} | ||
|
@@ -653,9 +661,22 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re | |
anteEvents = events.ToABCIEvents() | ||
} | ||
|
||
if mode == runTxModeCheck { | ||
err = app.mempool.Insert(ctx, tx.(mempool.Tx)) | ||
if err != nil { | ||
return gInfo, nil, anteEvents, priority, err | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between this and lines 678-683 below ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this doesn't look right @JeancarloBarrios. We should only be inserting into the app-side mempool on CheckTx once, which we already do below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree; sorry I have not fully updated this I will push a bit later today the implementation on likes 678-683has been removed. |
||
} else if mode == runTxModeDeliver { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my own understanding, why is it okay to not handle other types of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We remove during |
||
err = app.mempool.Remove(tx.(mempool.Tx)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if another node gossips a tx after it is delivered (and removed from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sergio-mena we're not relying or assuming anything about Tendermint here. IIRC, Tendermint reaps the txs from its mempool prior to making a block proposal. Thus, the txs should not be in its mempool and thus gossiped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things:
|
||
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) { | ||
return gInfo, nil, anteEvents, priority, | ||
fmt.Errorf("failed to remove tx from mempool: %w", err) | ||
} | ||
} | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// TODO remove nil check when implemented | ||
if mode == runTxModeCheck && app.mempool != nil { | ||
err = app.mempool.Insert(ctx, tx.(sdk.MempoolTx)) | ||
err = app.mempool.Insert(ctx, tx.(mempool.Tx)) | ||
if err != nil { | ||
return gInfo, nil, anteEvents, priority, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.