Skip to content
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

change base consensus from Ostracon to Tendermint v0.34.24 #1178

Merged
merged 7 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ linters-settings:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/Finschia/ostracon)
- prefix(github.com/Finschia/finschia-sdk)
revive:
rules:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased](https://github.com/Finschia/finschia-sdk/compare/v0.48.0...HEAD)

### Features
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24

### Improvements
* (docs) [\#1120](https://github.com/Finschia/finschia-sdk/pull/1120) Update links in x/foundation README.md
Expand All @@ -55,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Removed

### Breaking Changes
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24

### State Machine Breaking

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mocks: $(MOCKS_DIR)
mockgen -source=types/router.go -package mocks -destination tests/mocks/types_router.go
mockgen -source=types/handler.go -package mocks -destination tests/mocks/types_handler.go
mockgen -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server
mockgen -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/Finschia/ostracon/libs/log Logger
mockgen -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger
mockgen -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go
.PHONY: mocks

Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ The following work was carried out to improve performance.
- Use [fastcache](https://github.com/victoriametrics/fastcache) for inter block cache and nodedb cache of iavl
- Lock granularity enhancement

In addition, the following functions were added:

- Virtual machine using `cosmwasm` that makes smart contracts possible to be executed
- Use [Ostracon](https://github.com/Finschia/ostracon) as consensus engine instead of `Tendermint`


To learn about Cosmos SDK, please refer [Cosmos SDK Docs](https://github.com/cosmos/cosmos-sdk/blob/master/docs).

## Quick Start
Expand Down
84 changes: 24 additions & 60 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

ocabci "github.com/Finschia/ostracon/abci/types"

"github.com/Finschia/finschia-sdk/codec"
snapshottypes "github.com/Finschia/finschia-sdk/snapshots/types"
"github.com/Finschia/finschia-sdk/telemetry"
Expand Down Expand Up @@ -125,7 +123,7 @@ func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOp
}

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req ocabci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")

if app.cms.TracingEnabled() {
Expand All @@ -138,9 +136,6 @@ func (app *BaseApp) BeginBlock(req ocabci.RequestBeginBlock) (res abci.ResponseB
panic(err)
}

// set the signed validators for addition to context in deliverTx
app.voteInfos = req.LastCommitInfo.GetVotes()

// Initialize the DeliverTx state. If this is the first block, it should
// already be initialized in InitChain. Otherwise app.deliverState will be
// nil, since it is reset on Commit.
Expand All @@ -165,7 +160,6 @@ func (app *BaseApp) BeginBlock(req ocabci.RequestBeginBlock) (res abci.ResponseB
// NOTE: header hash is not set in NewContext, so we manually set it here

app.deliverState.ctx = app.deliverState.ctx.
WithVoteInfos(app.voteInfos).
WithBlockGasMeter(gasMeter).
WithHeaderHash(req.Hash).
WithConsensusParams(app.GetConsensusParams(app.deliverState.ctx))
Expand Down Expand Up @@ -228,63 +222,36 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc
// internal CheckTx state if the AnteHandler passes. Otherwise, the ResponseCheckTx
// will contain releveant error information. Regardless of tx execution outcome,
// the ResponseCheckTx will contain relevant gas execution context.
func (app *BaseApp) CheckTxSync(req abci.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx")

if req.Type != abci.CheckTxType_New && req.Type != abci.CheckTxType_Recheck {
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}
var mode runTxMode

tx, err := app.preCheckTx(req.Tx)
if err != nil {
return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
}
switch {
case req.Type == abci.CheckTxType_New:
mode = runTxModeCheck

waits, signals := app.checkAccountWGs.Register(tx)
case req.Type == abci.CheckTxType_Recheck:
mode = runTxModeReCheck

app.checkAccountWGs.Wait(waits)
defer app.checkAccountWGs.Done(signals)
default:
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}

gInfo, err := app.checkTx(req.Tx, tx, req.Type == abci.CheckTxType_Recheck)
gInfo, result, anteEvents, err := app.runTx(mode, req.Tx)
if err != nil {
return sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)
// return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace) // TODO(dudong2): need to fix to use ResponseCheckTxWithEvents
return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace)
}

return ocabci.ResponseCheckTx{
return abci.ResponseCheckTx{
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints?
Log: result.Log,
Data: result.Data,
Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents),
}
}

func (app *BaseApp) CheckTxAsync(req abci.RequestCheckTx, callback ocabci.CheckTxCallback) {
if req.Type != abci.CheckTxType_New && req.Type != abci.CheckTxType_Recheck {
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}

reqCheckTx := &RequestCheckTxAsync{
txBytes: req.Tx,
recheck: req.Type == abci.CheckTxType_Recheck,
callback: callback,
prepare: waitGroup1(),
}
app.chCheckTx <- reqCheckTx

go app.prepareCheckTx(reqCheckTx)
}

// BeginRecheckTx implements the ABCI interface and set the check state based on the given header
func (app *BaseApp) BeginRecheckTx(req ocabci.RequestBeginRecheckTx) ocabci.ResponseBeginRecheckTx {
// NOTE: This is safe because Ostracon holds a lock on the mempool for Rechecking.
app.setCheckState(req.Header)
return ocabci.ResponseBeginRecheckTx{Code: abci.CodeTypeOK}
}

// EndRecheckTx implements the ABCI interface.
func (app *BaseApp) EndRecheckTx(req ocabci.RequestEndRecheckTx) ocabci.ResponseEndRecheckTx {
return ocabci.ResponseEndRecheckTx{Code: abci.CodeTypeOK}
}

// DeliverTx implements the ABCI interface and executes a tx in DeliverTx mode.
// State only gets persisted if all messages are valid and get executed successfully.
// Otherwise, the ResponseDeliverTx will contain releveant error information.
Expand All @@ -311,12 +278,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted")
}()

tx, err := app.txDecoder(req.Tx)
if err != nil {
return sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace)
}

gInfo, result, anteEvents, err := app.runTx(req.Tx, tx, false)
gInfo, result, anteEvents, err := app.runTx(runTxModeDeliver, req.Tx)
if err != nil {
resultStr = "failed"
return sdkerrors.ResponseDeliverTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, sdk.MarkEventsToIndex(anteEvents, app.indexEvents), app.trace)
Expand Down Expand Up @@ -350,6 +312,12 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
commitID := app.cms.Commit()
app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID))

// Reset the Check state to the latest committed.
//
// NOTE: This is safe because Tendermint holds a lock on the mempool for
// Commit. Use the header from this latest block.
app.setCheckState(header)

// empty/reset the deliver state
app.deliverState = nil

Expand Down Expand Up @@ -690,11 +658,9 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
}

// branch the commit-multistore for safety
app.checkStateMtx.RLock()
ctx := sdk.NewContext(
cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger,
).WithMinGasPrices(app.minGasPrices).WithBlockHeight(height)
app.checkStateMtx.RUnlock()

return ctx, nil
}
Expand Down Expand Up @@ -928,11 +894,9 @@ func (app *BaseApp) createQueryContextWithCheckState() sdk.Context {
cacheMS := app.checkState.CacheMultiStore()

// branch the commit-multistore for safety
app.checkStateMtx.RLock()
ctx := sdk.NewContext(
cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger,
).WithMinGasPrices(app.minGasPrices).WithBlockHeight(app.LastBlockHeight())
app.checkStateMtx.RUnlock()

return ctx
}
12 changes: 5 additions & 7 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ocabci "github.com/Finschia/ostracon/abci/types"

sdk "github.com/Finschia/finschia-sdk/types"
)

Expand Down Expand Up @@ -143,10 +141,10 @@ func TestBaseAppCreateQueryContext(t *testing.T) {
err := app.init()
require.NoError(t, err)

app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.Commit()

app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.Commit()

testCases := []struct {
Expand Down Expand Up @@ -195,7 +193,7 @@ func TestBaseAppBeginBlockConsensusParams(t *testing.T) {
require.NoError(t, err)

// set block params
app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
ctx := app.deliverState.ctx
maxGas := int64(123456789)
app.paramStore.Set(ctx, ParamStoreKeyBlockParams,
Expand All @@ -205,8 +203,8 @@ func TestBaseAppBeginBlockConsensusParams(t *testing.T) {
app.Commit()

// confirm consensus params updated into the context
app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
newCtx := app.getContextForTx(app.checkState, []byte{})
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
newCtx := app.getContextForTx(runTxModeCheck, []byte{})
require.Equal(t, maxGas, newCtx.ConsensusParams().Block.MaxGas)
}

Expand Down
85 changes: 0 additions & 85 deletions baseapp/accountwgs.go

This file was deleted.

Loading