mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 13:55:17 +00:00
light: replace homegrown mock with mockery (#6735)
This pull request removes the homegrown mocks in `light/provider/mock` in favor of mockery mocks. Adds a simple benchmark only mock to avoid the overhead of `reflection` that `mockery` incurs. part of #5274
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
mockp "github.com/tendermint/tendermint/light/provider/mock"
|
||||
dbs "github.com/tendermint/tendermint/light/store/db"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// NOTE: block is produced every minute. Make sure the verification time
|
||||
@@ -21,12 +21,50 @@ import (
|
||||
// or -benchtime 100x.
|
||||
//
|
||||
// Remember that none of these benchmarks account for network latency.
|
||||
var (
|
||||
benchmarkFullNode = mockp.New(genMockNode(chainID, 1000, 100, 1, bTime))
|
||||
genesisBlock, _ = benchmarkFullNode.LightBlock(context.Background(), 1)
|
||||
)
|
||||
var ()
|
||||
|
||||
type providerBenchmarkImpl struct {
|
||||
currentHeight int64
|
||||
blocks map[int64]*types.LightBlock
|
||||
}
|
||||
|
||||
func newProviderBenchmarkImpl(headers map[int64]*types.SignedHeader,
|
||||
vals map[int64]*types.ValidatorSet) provider.Provider {
|
||||
impl := providerBenchmarkImpl{
|
||||
blocks: make(map[int64]*types.LightBlock, len(headers)),
|
||||
}
|
||||
for height, header := range headers {
|
||||
if height > impl.currentHeight {
|
||||
impl.currentHeight = height
|
||||
}
|
||||
impl.blocks[height] = &types.LightBlock{
|
||||
SignedHeader: header,
|
||||
ValidatorSet: vals[height],
|
||||
}
|
||||
}
|
||||
return &impl
|
||||
}
|
||||
|
||||
func (impl *providerBenchmarkImpl) LightBlock(ctx context.Context, height int64) (*types.LightBlock, error) {
|
||||
if height == 0 {
|
||||
return impl.blocks[impl.currentHeight], nil
|
||||
}
|
||||
lb, ok := impl.blocks[height]
|
||||
if !ok {
|
||||
return nil, provider.ErrLightBlockNotFound
|
||||
}
|
||||
return lb, nil
|
||||
}
|
||||
|
||||
func (impl *providerBenchmarkImpl) ReportEvidence(_ context.Context, _ types.Evidence) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func BenchmarkSequence(b *testing.B) {
|
||||
headers, vals, _ := genLightBlocksWithKeys(chainID, 1000, 100, 1, bTime)
|
||||
benchmarkFullNode := newProviderBenchmarkImpl(headers, vals)
|
||||
genesisBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 1)
|
||||
|
||||
c, err := light.NewClient(
|
||||
context.Background(),
|
||||
chainID,
|
||||
@@ -55,6 +93,10 @@ func BenchmarkSequence(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkBisection(b *testing.B) {
|
||||
headers, vals, _ := genLightBlocksWithKeys(chainID, 1000, 100, 1, bTime)
|
||||
benchmarkFullNode := newProviderBenchmarkImpl(headers, vals)
|
||||
genesisBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 1)
|
||||
|
||||
c, err := light.NewClient(
|
||||
context.Background(),
|
||||
chainID,
|
||||
@@ -82,7 +124,10 @@ func BenchmarkBisection(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkBackwards(b *testing.B) {
|
||||
headers, vals, _ := genLightBlocksWithKeys(chainID, 1000, 100, 1, bTime)
|
||||
benchmarkFullNode := newProviderBenchmarkImpl(headers, vals)
|
||||
trustedBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 0)
|
||||
|
||||
c, err := light.NewClient(
|
||||
context.Background(),
|
||||
chainID,
|
||||
|
||||
Reference in New Issue
Block a user