Skip to content

Commit

Permalink
Merge branch 'develop' into testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
iavl committed May 9, 2020
2 parents ccb2e63 + 5e59d7b commit e14a2c4
Show file tree
Hide file tree
Showing 590 changed files with 10,936 additions and 3,545 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
## [Unreleased]
### nchd

* add extension for IPAL transaction
* fix #33 unbonding failed
* update inflation of mint module
* add #34 upgrade module
* fix #27 "--gas=auto" not available
* fix #29 op blockhash
* fix #32 op timestamp
* support #30 revert reason provided by the contract
* update cli interaction with contract txs
* update inflation model and related query api

* add gas_price_threshold param for tx gas price limit


### nchcli v1.0.4

#### [Features]

* update response when query account not exist

* add distr alias for ```nchcli```

* support "--gas auto" for ```nchcli``` to calculate gas automatically

* add OOG logs in tx-receipt when out of gas

### nchd v1.0.4
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/make -f

PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')

Expand Down Expand Up @@ -88,3 +87,18 @@ draw-deps:

clean:
rm -rf build/



##############################################
### Test
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation' | grep -v mock | grep -v 'netcloth-chain/tests' | grep -v '/netcloth/netcloth-chain/crypto')
PACKAGES_CRYPTO=$(shell go list ./... | grep '/netcloth/netcloth-chain/crypto')

test: test_unit_crypto test_unit

test_unit:
@go test -mod=readonly $(PACKAGES_NOSIMULATION)

test_unit_crypto:
@go test -mod=readonly -tags "ledger test_ledger_mock" $(PACKAGES_CRYPTO)
115 changes: 72 additions & 43 deletions baseapp/abci.go → app/abci.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package baseapp
package app

import (
"fmt"
"os"
"sort"
"strconv"
"strings"

"github.com/netcloth/netcloth-chain/codec"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/netcloth/netcloth-chain/app/v0/auth"
"github.com/netcloth/netcloth-chain/codec"
sdk "github.com/netcloth/netcloth-chain/types"
sdkerrors "github.com/netcloth/netcloth-chain/types/errors"
"github.com/netcloth/netcloth-chain/version"
)

// InitChain implements the ABCI interface. It runs the initialization logic
// directly on the CommitMultiStore.
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
// stash the consensus params in the cms main store and memoize
// Stash the consensus params in the cms main store and memoize.
if req.ConsensusParams != nil {
app.setConsensusParams(req.ConsensusParams)
app.storeConsensusParams(req.ConsensusParams)
Expand All @@ -29,82 +29,79 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
app.setDeliverState(initHeader)
app.setCheckState(initHeader)

if app.initChainer == nil {
initChainer := app.Engine.GetCurrentProtocol().GetInitChainer()
if initChainer == nil {
return
}

// add block gas meter for any genesis transactions (allow infinite gas)
app.deliverState.ctx = app.deliverState.ctx.
WithBlockGasMeter(sdk.NewInfiniteGasMeter())
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())

res = app.initChainer(app.deliverState.ctx, req)
res = initChainer(app.deliverState.ctx, req)

// sanity check
if len(req.Validators) > 0 {
if len(req.Validators) != len(res.Validators) {
panic(fmt.Errorf(
"len(RequestInitChain.Validators) != len(validators) (%d != %d)",
len(req.Validators), len(res.Validators)))
panic(
fmt.Errorf(
"len(RequestInitChain.Validators) != len(GenesisValidators) (%d != %d)",
len(req.Validators), len(res.Validators),
),
)
}

sort.Sort(abci.ValidatorUpdates(req.Validators))
sort.Sort(abci.ValidatorUpdates(res.Validators))

for i, val := range res.Validators {
if !val.Equal(req.Validators[i]) {
panic(fmt.Errorf("validators[%d] != req.Validators[%d] ", i, i))
panic(fmt.Errorf("genesisValidators[%d] != req.Validators[%d] ", i, i))
}
}
}
// There may be some application state in the genesis file, so always init the metrics.
//app.Engine.GetCurrentProtocol().InitMetrics(app.cms)

// NOTE: We don't commit, but BeginBlock for block 1 starts from this
// deliverState.
return
}

// Info implements the ABCI interface.
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo {
lastCommitID := app.cms.LastCommitID()

return abci.ResponseInfo{
AppVersion: version.AppVersion,
Data: app.name,
LastBlockHeight: lastCommitID.Version,
LastBlockAppHash: lastCommitID.Hash,
}
}

// SetOption implements the ABCI interface.
func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOption) {
// TODO: Implement!
return
}

// FilterPeerByAddrPort filters peers by address/port.
func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery {
if app.addrPeerFilter != nil {
return app.addrPeerFilter(info)
}
return abci.ResponseQuery{}
}

// FilterPeerByIDfilters peers by node ID.
func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
if app.idPeerFilter != nil {
return app.idPeerFilter(info)
}
return abci.ResponseQuery{}
}

// Splits a string path using the delimiter '/'.
// e.g. "this/is/funny" becomes []string{"this", "is", "funny"}
func splitPath(requestPath string) (path []string) {
path = strings.Split(requestPath, "/")
// first element is empty string
if len(path) > 0 && path[0] == "" {
path = path[1:]
}
return path
}

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
if app.cms.TracingEnabled() {
app.cms.SetTracingContext(sdk.TraceContext(
Expand All @@ -129,7 +126,6 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
WithBlockHeight(req.Header.Height)
}

// add block gas meter
var gasMeter sdk.GasMeter
if maxGas := app.getMaximumBlockGas(); maxGas > 0 {
gasMeter = sdk.NewGasMeter(maxGas)
Expand All @@ -139,23 +135,50 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg

app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(gasMeter)

if app.beginBlocker != nil {
res = app.beginBlocker(app.deliverState.ctx, req)
beginBlocker := app.Engine.GetCurrentProtocol().GetBeginBlocker()
if beginBlocker != nil {
res = beginBlocker(app.deliverState.ctx, req)
}

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

// EndBlock implements the ABCI interface.
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
if app.deliverState.ms.TracingEnabled() {
app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore)
}

if app.endBlocker != nil {
res = app.endBlocker(app.deliverState.ctx, req)
endBlocker := app.Engine.GetCurrentProtocol().GetEndBlocker()
if endBlocker != nil {
res = endBlocker(app.deliverState.ctx, req)
}

appVersion := app.Engine.GetCurrentVersion()
for _, event := range res.Events {
if event.Type == sdk.AppVersionEvent {
for _, attr := range event.Attributes {
if string(attr.Key) == sdk.AppVersionEvent {
appVersion, _ = strconv.ParseUint(string(attr.Value), 10, 64)
break
}
}

break
}
}

if appVersion <= app.Engine.GetCurrentVersion() {
return
}

success := app.Engine.Activate(appVersion, app.deliverState.ctx)
if success {
app.txDecoder = auth.DefaultTxDecoder(app.Engine.GetCurrentProtocol().GetCodec())
return
} else {
fmt.Println(fmt.Sprintf("activate version from %d to %d failed, please upgrade your app", app.Engine.GetCurrentVersion(), appVersion))
}

return
Expand Down Expand Up @@ -191,19 +214,18 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx)
}

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

// DeliverTx implements the ABCI interface.
func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
tx, err := app.txDecoder(req.Tx)
if err != nil {
return sdkerrors.ResponseDeliverTx(err, 0, 0, err.Error())
return sdkerrors.ResponseDeliverTx(err, nil, 0, 0, err.Error())
}

gInfo, result, err := app.runTx(runTxModeDeliver, req.Tx, tx)
Expand All @@ -213,12 +235,18 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv
if result != nil {
log = result.Log
}
return sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, log)

var data []byte
if result != nil {
data = append(data, result.Data...)
}

return sdkerrors.ResponseDeliverTx(err, data, gInfo.GasWanted, gInfo.GasUsed, log)
}

return abci.ResponseDeliverTx{
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints?
GasWanted: int64(gInfo.GasWanted),
GasUsed: int64(gInfo.GasUsed),
Log: result.Log,
Data: result.Data,
Events: result.Events.ToABCIEvents(),
Expand Down Expand Up @@ -270,7 +298,6 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
}

switch path[0] {
// "/app" prefix for special application queries
case "app":
return handleQueryApp(app, path, req)

Expand Down Expand Up @@ -300,6 +327,10 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc

gInfo, _, _ := app.Simulate(txBytes, tx)

if req.Height == 0 {
req.Height = app.LastBlockHeight()
}

return abci.ResponseQuery{
Codespace: sdkerrors.RootCodespace,
Height: req.Height,
Expand All @@ -326,15 +357,13 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
}

func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery {
// "/store" prefix for store queries
queryable, ok := app.cms.(sdk.Queryable)
if !ok {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "multistore doesn't support queries"))
}

req.Path = "/" + strings.Join(path[1:], "/")

// when a client did not provide a query height, manually inject the latest
if req.Height == 0 {
req.Height = app.LastBlockHeight()
}
Expand Down Expand Up @@ -390,12 +419,12 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no route for custom query specified"))
}

querier := app.queryRouter.Route(path[1])
router := app.Engine.GetCurrentProtocol().GetQueryRouter()
querier := router.Route(path[1])
if querier == nil {
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "no custom querier found for route %s", path[1]))
}

// when a client did not provide a query height, manually inject the latest
if req.Height == 0 {
req.Height = app.LastBlockHeight()
}
Expand Down

0 comments on commit e14a2c4

Please sign in to comment.