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: expose InitChain tx responses #1941

Merged
merged 32 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7be8225
feat: expose InitChain response
n0izn0iz Apr 17, 2024
667f8bd
Merge branch 'master' into expose-genesis-response
n0izn0iz Apr 17, 2024
9107f45
tmp: start try to store results like in ApplyBlock
n0izn0iz Jun 10, 2024
8bcee48
chore: Merge remote-tracking branch 'origin/master' into expose-genes…
n0izn0iz Jun 10, 2024
8fa79be
feat: save InitChain's ResponseDeliverTxs and add test
n0izn0iz Jun 10, 2024
e4dd0f6
chore: clean
n0izn0iz Jun 10, 2024
d0da512
fix: preserve existing getHeight behavior
n0izn0iz Jun 10, 2024
15e974b
chore: improve comment
n0izn0iz Jun 10, 2024
6c41220
chore: self-contained tests
n0izn0iz Jun 11, 2024
13be10f
chore: remove artifact
n0izn0iz Jun 11, 2024
366d229
chore: use testing utils
n0izn0iz Jun 11, 2024
404fcd5
chore: move MockApplication into testing package
n0izn0iz Jun 12, 2024
926e226
chore: inline asserts
n0izn0iz Jun 12, 2024
d625a9a
Merge branch 'master' into expose-genesis-response
n0izn0iz Jun 12, 2024
f2923e8
Merge branch 'master' into expose-genesis-response
n0izn0iz Jun 12, 2024
a182a3a
chore: update proto
n0izn0iz Jun 12, 2024
0d1a4bd
Merge branch 'master' into expose-genesis-response
n0izn0iz Jun 17, 2024
9d309b7
Merge branch 'master' into expose-genesis-response
n0izn0iz Jun 19, 2024
eda735b
Merge branch 'master' into expose-genesis-response
n0izn0iz Jun 19, 2024
c5357f1
Merge branch 'master' into expose-genesis-response
n0izn0iz Jun 19, 2024
d684021
Merge branch 'master' into expose-genesis-response
n0izn0iz Jul 17, 2024
87fe7d8
chore: use t.Cleanup
n0izn0iz Jul 17, 2024
8b33ffc
chore: use cast instead of generic
n0izn0iz Jul 17, 2024
bad682a
chore: add getHeight test
n0izn0iz Jul 17, 2024
409cd9d
Merge branch 'master' into expose-genesis-response
n0izn0iz Jul 17, 2024
5cec713
Merge branch 'master' into expose-genesis-response
n0izn0iz Jul 19, 2024
ecdf0f2
Merge branch 'master' into expose-genesis-response
n0izn0iz Jul 19, 2024
973a73f
Merge branch 'master' into expose-genesis-response
n0izn0iz Jul 22, 2024
110da7d
chore: revert getHeight
n0izn0iz Jul 22, 2024
01dc6f8
chore: remove MockApplication
n0izn0iz Jul 22, 2024
e649de5
chore: SaveABCIResponses internal usage note
n0izn0iz Jul 22, 2024
83dd5a0
Merge branch 'master' into expose-genesis-response
n0izn0iz Jul 22, 2024
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
9 changes: 8 additions & 1 deletion gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
}

// Run genesis txs.
txResponses := make([]abci.ResponseDeliverTx, 0, len(genState.Txs))

Check warning on line 171 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L171

Added line #L171 was not covered by tests
for _, tx := range genState.Txs {
res := baseApp.Deliver(tx)
if res.IsErr() {
Expand All @@ -180,11 +181,17 @@
}

resHandler(ctx, tx, res)
txResponses = append(txResponses, abci.ResponseDeliverTx{
thehowl marked this conversation as resolved.
Show resolved Hide resolved
ResponseBase: res.ResponseBase,
GasWanted: res.GasWanted,
GasUsed: res.GasUsed,
})

Check warning on line 188 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L184-L188

Added lines #L184 - L188 were not covered by tests
}

// Done!
return abci.ResponseInitChain{
Validators: req.Validators,
Validators: req.Validators,
TxResponses: txResponses,

Check warning on line 194 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L193-L194

Added lines #L193 - L194 were not covered by tests
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tm2/pkg/bft/abci/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type ResponseInitChain struct {
ResponseBase
ConsensusParams *ConsensusParams
Validators []ValidatorUpdate
TxResponses []ResponseDeliverTx
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
}

type ResponseQuery struct {
Expand Down
11 changes: 11 additions & 0 deletions tm2/pkg/bft/consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"reflect"
"time"

"github.com/gnolang/gno/tm2/pkg/amino"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
"github.com/gnolang/gno/tm2/pkg/bft/appconn"
cstypes "github.com/gnolang/gno/tm2/pkg/bft/consensus/types"
Expand Down Expand Up @@ -306,6 +307,7 @@
if err != nil {
return nil, err
}
saveGenesisRes(h.stateDB, &res)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

if stateBlockHeight == 0 { // we only update state when we are in initial state
// If the app returned validators or consensus params, update the state.
Expand Down Expand Up @@ -393,6 +395,15 @@
appBlockHeight, storeBlockHeight, stateBlockHeight))
}

// panics if failed to marshal the given genesis response
func saveGenesisRes(db dbm.DB, res *abci.ResponseInitChain) {
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
b, err := amino.MarshalJSON(res)
if err != nil {
panic(fmt.Sprintf("Failed to save genesis response due to marshaling error: %v", err))

Check warning on line 402 in tm2/pkg/bft/consensus/replay.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/consensus/replay.go#L402

Added line #L402 was not covered by tests
}
db.SetSync([]byte("genesisRes"), b)
}

func (h *Handshaker) replayBlocks(state sm.State, proxyApp appconn.AppConns, appBlockHeight, storeBlockHeight int64, mutateState bool) ([]byte, error) {
// App is further behind than it should be, so we need to replay blocks.
// We replay all blocks from appBlockHeight+1.
Expand Down
24 changes: 23 additions & 1 deletion tm2/pkg/bft/rpc/core/net.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package core

import (
"fmt"

"github.com/gnolang/gno/tm2/pkg/amino"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
ctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
rpctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/types"
dbm "github.com/gnolang/gno/tm2/pkg/db"
"github.com/gnolang/gno/tm2/pkg/errors"
)

Expand Down Expand Up @@ -251,5 +256,22 @@
//
// ```
func Genesis(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) {
return &ctypes.ResultGenesis{Genesis: genDoc}, nil
res, err := loadGenesisRes(stateDB)
if err != nil {
return nil, err

Check warning on line 261 in tm2/pkg/bft/rpc/core/net.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/core/net.go#L259-L261

Added lines #L259 - L261 were not covered by tests
}
return &ctypes.ResultGenesis{Genesis: genDoc, Response: res}, nil

Check warning on line 263 in tm2/pkg/bft/rpc/core/net.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/core/net.go#L263

Added line #L263 was not covered by tests
}

func loadGenesisRes(db dbm.DB) (*abci.ResponseInitChain, error) {
b := db.Get([]byte("genesisRes"))
if len(b) == 0 {
return nil, errors.New("Genesis res not found")

Check warning on line 269 in tm2/pkg/bft/rpc/core/net.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/core/net.go#L266-L269

Added lines #L266 - L269 were not covered by tests
}
var genRes *abci.ResponseInitChain
err := amino.UnmarshalJSON(b, &genRes)
if err != nil {
panic(fmt.Sprintf("Failed to load genesis res due to unmarshaling error: %v (bytes: %X)", err, b))

Check warning on line 274 in tm2/pkg/bft/rpc/core/net.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/core/net.go#L271-L274

Added lines #L271 - L274 were not covered by tests
}
return genRes, nil

Check warning on line 276 in tm2/pkg/bft/rpc/core/net.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/core/net.go#L276

Added line #L276 was not covered by tests
}
3 changes: 2 additions & 1 deletion tm2/pkg/bft/rpc/core/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type ResultBlockchainInfo struct {

// Genesis file
type ResultGenesis struct {
Genesis *types.GenesisDoc `json:"genesis"`
Genesis *types.GenesisDoc `json:"genesis"`
Response *abci.ResponseInitChain `json:"response"`
}

// Single block (with meta)
Expand Down
Loading