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

feat: integrate ostracon #317

Merged
merged 15 commits into from
Sep 10, 2021
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-arch: ["amd64", "arm", "arm64"]
include:
- goarch: "amd64"
gcc: "gcc"
package: ""
- goarch: "arm64"
gcc: "aarch64-linux-gnu-gcc"
package: "g++-aarch64-linux-gnu"
- goarch: "arm"
gcc: "arm-linux-gnueabi-gcc"
package: "g++-arm-linux-gnueabi"
steps:
- run: sudo apt update && sudo apt install -y ${{ matrix.package }} qemu-user-binfmt
if: "matrix.package != ''"
- uses: actions/checkout@v2
- uses: actions/setup-go@v2.1.3
with:
Expand All @@ -52,7 +63,7 @@ jobs:
go.mod
go.sum
- name: Build
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build
run: GOOS=linux CGO_ENABLED=1 GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} LEDGER_ENABLED=false make build

# TODO: disable test-race. please enable this after fixing concurrent checkTx
# test-cosmovisor:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* (api) [\#130](https://github.com/line/lfb-sdk/pull/130) Rename rest apis
* (auth) [\#265](https://github.com/line/lfb-sdk/pull/265) Introduce sig block height for the new replay protection
* (global) [\#298](https://github.com/line/lfb-sdk/pull/298) Treat addresses as strings
* (ostracon) [\#317](https://github.com/line/lfb-sdk/pull/317) Integrate Ostracon including vrf election and voter concept

### Build, CI
* (ci) [\#234](https://github.com/line/lfb-sdk/pull/234) Fix branch name in ci script
Expand Down
6 changes: 3 additions & 3 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gogo/protobuf/proto"
abci "github.com/line/ostracon/abci/types"
ostproto "github.com/line/ostracon/proto/ostracon/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

Expand All @@ -28,13 +28,13 @@ import (
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
// On a new chain, we consider the init chain block height as 0, even though
// req.InitialHeight is 1 by default.
initHeader := ostproto.Header{ChainID: req.ChainId, Time: req.Time}
initHeader := ocproto.Header{ChainID: req.ChainId, Time: req.Time}

// If req.InitialHeight is > 1, then we set the initial version in the
// stores.
if req.InitialHeight > 1 {
app.initialHeight = req.InitialHeight
initHeader = ostproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time}
initHeader = ocproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time}
err := app.cms.SetInitialVersion(req.InitialHeight)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

abci "github.com/line/ostracon/abci/types"
ostprototypes "github.com/line/ostracon/proto/ostracon/types"
ocprototypes "github.com/line/ostracon/proto/ostracon/types"
"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -106,7 +106,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
tc.bapp.SetParamStore(&paramStore{db: memdb.NewDB()})
tc.bapp.InitChain(abci.RequestInitChain{
ConsensusParams: &abci.ConsensusParams{
Evidence: &ostprototypes.EvidenceParams{
Evidence: &ocprototypes.EvidenceParams{
MaxAgeNumBlocks: tc.maxAgeBlocks,
},
},
Expand Down
12 changes: 6 additions & 6 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
abci "github.com/line/ostracon/abci/types"
"github.com/line/ostracon/crypto/tmhash"
"github.com/line/ostracon/libs/log"
ostproto "github.com/line/ostracon/proto/ostracon/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
tmdb "github.com/line/tm-db/v2"

"github.com/line/lfb-sdk/codec/types"
Expand Down Expand Up @@ -274,7 +274,7 @@ func (app *BaseApp) init() error {
}

// needed for the export command which inits from store but never calls initchain
app.setCheckState(ostproto.Header{})
app.setCheckState(ocproto.Header{})
app.Seal()

// make sure the snapshot interval is a multiple of the pruning KeepEvery interval
Expand Down Expand Up @@ -350,7 +350,7 @@ func (app *BaseApp) IsSealed() bool { return app.sealed }
// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch,
// provided header, and minimum gas prices set. It is set on InitChain and reset
// on Commit.
func (app *BaseApp) setCheckState(header ostproto.Header) {
func (app *BaseApp) setCheckState(header ocproto.Header) {
ms := app.cms.CacheMultiStore()
app.checkStateMtx.Lock()
defer app.checkStateMtx.Unlock()
Expand All @@ -369,7 +369,7 @@ func (app *BaseApp) setCheckState(header ostproto.Header) {
// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch,
// and provided header. It is set on InitChain and BeginBlock and set to nil on
// Commit.
func (app *BaseApp) setDeliverState(header ostproto.Header) {
func (app *BaseApp) setDeliverState(header ocproto.Header) {
ms := app.cms.CacheMultiStore()
app.deliverState = &state{
ms: ms,
Expand All @@ -394,14 +394,14 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *abci.ConsensusParams {
}

if app.paramStore.Has(ctx, ParamStoreKeyEvidenceParams) {
var ep ostproto.EvidenceParams
var ep ocproto.EvidenceParams

app.paramStore.Get(ctx, ParamStoreKeyEvidenceParams, &ep)
cp.Evidence = &ep
}

if app.paramStore.Has(ctx, ParamStoreKeyValidatorParams) {
var vp ostproto.ValidatorParams
var vp ocproto.ValidatorParams

app.paramStore.Get(ctx, ParamStoreKeyValidatorParams, &vp)
cp.Validator = &vp
Expand Down
50 changes: 25 additions & 25 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/gogo/protobuf/jsonpb"
abci "github.com/line/ostracon/abci/types"
"github.com/line/ostracon/libs/log"
ostproto "github.com/line/ostracon/proto/ostracon/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
tmdb "github.com/line/tm-db/v2"
"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -76,7 +76,7 @@ func (ps *paramStore) Get(_ sdk.Context, key []byte, ptr interface{}) {
}

func defaultLogger() log.Logger {
return log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
return log.NewOCLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
}

func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp {
Expand Down Expand Up @@ -154,7 +154,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
r := rand.New(rand.NewSource(3920758213583))
keyCounter := 0
for height := int64(1); height <= int64(blocks); height++ {
app.BeginBlock(abci.RequestBeginBlock{Header: ostproto.Header{Height: height}})
app.BeginBlock(abci.RequestBeginBlock{Header: ocproto.Header{Height: height}})
for txNum := 0; txNum < blockTxs; txNum++ {
tx := txTest{Msgs: []sdk.Msg{}}
for msgNum := 0; msgNum < 100; msgNum++ {
Expand Down Expand Up @@ -225,13 +225,13 @@ func TestLoadVersion(t *testing.T) {
require.Equal(t, emptyCommitID, lastID)

// execute a block, collect commit ID
header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res := app.Commit()
commitID1 := sdk.CommitID{Version: 1, Hash: res.Data}

// execute a block, collect commit ID
header = ostproto.Header{Height: 2}
header = ocproto.Header{Height: 2}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res = app.Commit()
commitID2 := sdk.CommitID{Version: 2, Hash: res.Data}
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestSetLoader(t *testing.T) {
require.Nil(t, err)

// "execute" one block
app.BeginBlock(abci.RequestBeginBlock{Header: ostproto.Header{Height: 2}})
app.BeginBlock(abci.RequestBeginBlock{Header: ocproto.Header{Height: 2}})
res := app.Commit()
require.NotNil(t, res.Data)

Expand Down Expand Up @@ -375,7 +375,7 @@ func TestLoadVersionInvalid(t *testing.T) {
err = app.LoadVersion(-1)
require.Error(t, err)

header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
res := app.Commit()
commitID1 := sdk.CommitID{Version: 1, Hash: res.Data}
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestLoadVersionPruning(t *testing.T) {
// Commit seven blocks, of which 7 (latest) is kept in addition to 6, 5
// (keep recent) and 3 (keep every).
for i := int64(1); i <= 7; i++ {
app.BeginBlock(abci.RequestBeginBlock{Header: ostproto.Header{Height: i}})
app.BeginBlock(abci.RequestBeginBlock{Header: ocproto.Header{Height: i}})
res := app.Commit()
lastCommitID = sdk.CommitID{Version: i, Hash: res.Data}
}
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestInitChainer(t *testing.T) {
require.Equal(t, value, res.Value)

// commit and ensure we can still query
header := ostproto.Header{Height: app.LastBlockHeight() + 1}
header := ocproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
app.Commit()

Expand Down Expand Up @@ -662,14 +662,14 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) {

require.PanicsWithError(t, "invalid height: 4; expected: 3", func() {
app.BeginBlock(abci.RequestBeginBlock{
Header: ostproto.Header{
Header: ocproto.Header{
Height: 4,
},
})
})

app.BeginBlock(abci.RequestBeginBlock{
Header: ostproto.Header{
Header: ocproto.Header{
Height: 3,
},
})
Expand Down Expand Up @@ -951,7 +951,7 @@ func TestCheckTx(t *testing.T) {
require.Equal(t, nTxs, storedCounter)

// If a block is committed, CheckTx state should be reset.
header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
app.EndBlock(abci.RequestEndBlock{})
app.Commit()
Expand Down Expand Up @@ -990,7 +990,7 @@ func TestDeliverTx(t *testing.T) {
txPerHeight := 5

for blockN := 0; blockN < nBlocks; blockN++ {
header := ostproto.Header{Height: int64(blockN) + 1}
header := ocproto.Header{Height: int64(blockN) + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

for i := 0; i < txPerHeight; i++ {
Expand Down Expand Up @@ -1044,7 +1044,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
// run a multi-msg tx
// with all msgs the same route

header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
tx := newTxCounter(0, 0, 1, 2)
txBytes, err := codec.MarshalBinaryBare(tx)
Expand Down Expand Up @@ -1125,7 +1125,7 @@ func TestSimulateTx(t *testing.T) {
nBlocks := 3
for blockN := 0; blockN < nBlocks; blockN++ {
count := int64(blockN + 1)
header := ostproto.Header{Height: count}
header := ocproto.Header{Height: count}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

tx := newTxCounter(count, count)
Expand Down Expand Up @@ -1180,7 +1180,7 @@ func TestRunInvalidTransaction(t *testing.T) {

app := setupBaseApp(t, anteOpt, routerOpt)

header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

// transaction with no messages
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func TestTxGasLimits(t *testing.T) {

app := setupBaseApp(t, anteOpt, routerOpt)

header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

testCases := []struct {
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func TestMaxBlockGasLimits(t *testing.T) {
tx := tc.tx

// reset the block gas
header := ostproto.Header{Height: app.LastBlockHeight() + 1}
header := ocproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

// execute the transaction multiple times
Expand Down Expand Up @@ -1475,7 +1475,7 @@ func TestCustomRunTxPanicHandler(t *testing.T) {

app := setupBaseApp(t, anteOpt, routerOpt)

header := ostproto.Header{Height: 1}
header := ocproto.Header{Height: 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

app.AddRunTxRecoveryHandler(func(recoveryObj interface{}) error {
Expand Down Expand Up @@ -1517,7 +1517,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
app.InitChain(abci.RequestInitChain{})
registerTestCodec(cdc)

header := ostproto.Header{Height: app.LastBlockHeight() + 1}
header := ocproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

// execute a tx that will fail ante handler execution
Expand Down Expand Up @@ -1625,7 +1625,7 @@ func TestGasConsumptionBadTx(t *testing.T) {

app.InitChain(abci.RequestInitChain{})

header := ostproto.Header{Height: app.LastBlockHeight() + 1}
header := ocproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

tx := newTxCounter(5, 0)
Expand Down Expand Up @@ -1689,7 +1689,7 @@ func TestQuery(t *testing.T) {
require.Equal(t, 0, len(res.Value))

// query is still empty after a DeliverTx before we commit
header := ostproto.Header{Height: app.LastBlockHeight() + 1}
header := ocproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

_, resTx, err := app.Deliver(aminoTxEncoder(), tx)
Expand All @@ -1715,7 +1715,7 @@ func TestGRPCQuery(t *testing.T) {
app := setupBaseApp(t, grpcQueryOpt)

app.InitChain(abci.RequestInitChain{})
header := ostproto.Header{Height: app.LastBlockHeight() + 1}
header := ocproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
app.Commit()

Expand Down Expand Up @@ -1772,7 +1772,7 @@ func TestP2PQuery(t *testing.T) {
func TestGetMaximumBlockGas(t *testing.T) {
app := setupBaseApp(t)
app.InitChain(abci.RequestInitChain{})
ctx := app.NewContext(true, ostproto.Header{})
ctx := app.NewContext(true, ocproto.Header{})

app.StoreConsensusParams(ctx, &abci.ConsensusParams{Block: &abci.BlockParams{MaxGas: 0}})
require.Equal(t, uint64(0), app.getMaximumBlockGas(ctx))
Expand Down Expand Up @@ -1990,7 +1990,7 @@ func TestWithRouter(t *testing.T) {
txPerHeight := 5

for blockN := 0; blockN < nBlocks; blockN++ {
header := ostproto.Header{Height: int64(blockN) + 1}
header := ocproto.Header{Height: int64(blockN) + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})

for i := 0; i < txPerHeight; i++ {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/grpcrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestRegisterQueryServiceTwice(t *testing.T) {
// Setup baseapp.
db := memdb.NewDB()
encCfg := simapp.MakeTestEncodingConfig()
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
app := baseapp.NewBaseApp("test", log.NewOCLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)

Expand Down
Loading