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

Introduce safe state to unit tests #38

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
476ed9f
introduce safe state to prevent data race
Jun 21, 2024
075ae5c
rpc table test
vasylNaumenko May 3, 2024
da6f485
preliminary version of combination of table tests, and business logic…
May 8, 2024
c2bd13d
draft unit tests
May 14, 2024
927ffb0
proxy app checkTx empty response
May 14, 2024
da2b026
add implementation of test abci service
May 15, 2024
f8ebd06
add flexibility to imitate block build process
May 16, 2024
a3eeb5b
add Id param to BlockAccept call
May 16, 2024
906232d
add status service test
May 21, 2024
9533cf0
key encoding to hex
May 23, 2024
12540fc
fix mistake: mempool size will not increase after build block
May 23, 2024
6b22b0e
finalize network service unit test
May 27, 2024
f5f8078
finalize status service unit test
May 27, 2024
80a79ea
preliminary version of history and sign client
May 30, 2024
ac2f226
finalize tests for history client
Jun 4, 2024
cabd636
compare app hash of block to previous state
Jun 6, 2024
dfe0720
fix test block production
Jun 6, 2024
213a2e3
introduce test block results
Jun 10, 2024
23999f7
implement BlockSearch unit test
Jun 10, 2024
100d43b
implement TxSearch unit test
Jun 10, 2024
1eb6ac6
implement commit rpc unit test
Jun 10, 2024
d690c51
fix block by hash params input to appropriate format
Jun 11, 2024
725568d
introduce unconfirmed txs unit test
Jun 11, 2024
144c9e3
check tx unit test implementation
Jun 12, 2024
414f170
add test cases for Check Tx unit test
Jun 13, 2024
c71e9b8
put off checks of unimplemented rpc tests until later. Clean up code
Jun 18, 2024
193e06c
fix U1000 staticcheck: use unused non-imported tests
Jun 19, 2024
09343c2
get rid of new block unnecessary log
Jun 20, 2024
471b779
wait for state to be updated
Jun 20, 2024
21d7485
use safe state of vm in unit tests
Jun 23, 2024
be58ed4
update state instead of create new state; rename field of vm
Jun 23, 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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand Down
3 changes: 1 addition & 2 deletions jsonrpc/http_json_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
cache = false
}

logger.Info("calling func", "method", request.Method, "args", args)
returns := rpcFunc.f.Call(args)
result, err := unreflectResult(returns)
logger.Info("result of calling func for %s: err: %s", request.Method, err)

if err != nil {
logger.Debug("unexpected result", "method", request.Method, "err", err)
responses = append(responses, types.RPCInternalError(request.ID, err))
continue
}
Expand Down
67 changes: 67 additions & 0 deletions safestate/safestate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package safestate

import (
"github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/types"
"sync"
)

type SafeState struct {
state.State
mtx *sync.RWMutex
}

func New(state state.State) SafeState {
return SafeState{
State: state,
mtx: &sync.RWMutex{},
}
}

func (ss *SafeState) StateCopy() state.State {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State
}

func (ss *SafeState) StateBytes() []byte {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State.Bytes()
}

func (ss *SafeState) UpdateState(cmtState state.State) {
ss.mtx.Lock()
defer ss.mtx.Unlock()
ss.State = cmtState
}

func (ss *SafeState) LastBlockHeight() int64 {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State.LastBlockHeight
}

func (ss *SafeState) LastBlockID() types.BlockID {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State.LastBlockID
}

func (ss *SafeState) Validators() *types.ValidatorSet {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State.Validators
}

func (ss *SafeState) AppHash() []byte {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State.AppHash
}

func (ss *SafeState) ChainID() string {
ss.mtx.RLock()
defer ss.mtx.RUnlock()
return ss.State.ChainID
}
6 changes: 3 additions & 3 deletions vm/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (rpc *RPC) Routes() map[string]*jsonrpc.RPCFunc {
"commit": jsonrpc.NewRPCFunc(rpc.Commit, "height", jsonrpc.Cacheable("height")),
// "header": jsonrpc.NewRPCFunc(rpc.Header, "height", jsonrpc.Cacheable("height")),
// "header_by_hash": jsonrpc.NewRPCFunc(rpc.HeaderByHash, "hash", jsonrpc.Cacheable()),
"check_tx": jsonrpc.NewRPCFunc(rpc.CheckTx, "tx"),
"tx": jsonrpc.NewRPCFunc(rpc.Tx, "hash,prove", jsonrpc.Cacheable()),
// "consensus_state": jsonrpc.NewRPCFunc(rpc.GetConsensusState, ""),
"check_tx": jsonrpc.NewRPCFunc(rpc.CheckTx, "tx"),
"tx": jsonrpc.NewRPCFunc(rpc.Tx, "hash,prove", jsonrpc.Cacheable()),
"consensus_state": jsonrpc.NewRPCFunc(rpc.GetConsensusState, ""),
"unconfirmed_txs": jsonrpc.NewRPCFunc(rpc.UnconfirmedTxs, "limit"),
"num_unconfirmed_txs": jsonrpc.NewRPCFunc(rpc.NumUnconfirmedTxs, ""),
"tx_search": jsonrpc.NewRPCFunc(rpc.TxSearch, "query,prove,page,per_page,order_by"),
Expand Down
Loading
Loading