Skip to content

Commit 86e23b4

Browse files
author
Daisuke Kanda
committed
add debug prover and debug chain module for testing fake lost of chain state
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
1 parent 2f856cc commit 86e23b4

File tree

17 files changed

+1226
-28
lines changed

17 files changed

+1226
-28
lines changed

chains/debug/chain.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package debug
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/cosmos/cosmos-sdk/codec"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
10+
11+
"github.com/hyperledger-labs/yui-relayer/core"
12+
)
13+
14+
type Chain struct {
15+
config ChainConfig
16+
OriginChain core.Chain
17+
}
18+
19+
var _ core.Chain = (*Chain)(nil)
20+
21+
func (c *Chain) ChainID() string {
22+
return c.OriginChain.ChainID()
23+
}
24+
25+
func (c *Chain) Config() ChainConfig {
26+
return c.config
27+
}
28+
29+
func (c *Chain) Codec() codec.ProtoCodecMarshaler {
30+
return c.OriginChain.Codec()
31+
}
32+
33+
func (c *Chain) GetAddress() (sdk.AccAddress, error) {
34+
return c.OriginChain.GetAddress()
35+
}
36+
37+
// SetRelayInfo sets source's path and counterparty's info to the chain
38+
func (c *Chain) SetRelayInfo(path *core.PathEnd, counterparty *core.ProvableChain, counterpartyPath *core.PathEnd) error {
39+
return c.OriginChain.SetRelayInfo(path, counterparty, counterpartyPath)
40+
}
41+
42+
func (c *Chain) Path() *core.PathEnd {
43+
return c.OriginChain.Path()
44+
}
45+
46+
func (c *Chain) Init(homePath string, timeout time.Duration, codec codec.ProtoCodecMarshaler, debug bool) error {
47+
return c.OriginChain.Init(homePath, timeout, codec, debug)
48+
}
49+
50+
func (c *Chain) SetupForRelay(ctx context.Context) error {
51+
return c.OriginChain.SetupForRelay(ctx)
52+
}
53+
54+
// LatestHeight queries the chain for the latest height and returns it
55+
func (c *Chain) LatestHeight(ctx context.Context) (ibcexported.Height, error) {
56+
return c.OriginChain.LatestHeight(ctx)
57+
}
58+
59+
func (c *Chain) Timestamp(ctx context.Context, height ibcexported.Height) (time.Time, error) {
60+
return c.OriginChain.Timestamp(ctx, height)
61+
}
62+
63+
func (c *Chain) AverageBlockTime() time.Duration {
64+
return c.OriginChain.AverageBlockTime()
65+
}
66+
67+
func (c *Chain) RegisterMsgEventListener(listener core.MsgEventListener) {
68+
c.OriginChain.RegisterMsgEventListener(listener)
69+
}
70+
71+
func (c *Chain) SendMsgs(ctx context.Context, msgs []sdk.Msg) ([]core.MsgID, error) {
72+
return c.OriginChain.SendMsgs(ctx, msgs)
73+
}
74+
75+
func (c *Chain) GetMsgResult(ctx context.Context, id core.MsgID) (core.MsgResult, error) {
76+
return c.OriginChain.GetMsgResult(ctx, id)
77+
}

chains/debug/codec.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package debug
2+
3+
import (
4+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
5+
"github.com/hyperledger-labs/yui-relayer/core"
6+
)
7+
8+
// RegisterInterfaces register the module interfaces to protobuf
9+
// Any.
10+
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
11+
registry.RegisterImplementations(
12+
(*core.ChainConfig)(nil),
13+
&ChainConfig{},
14+
)
15+
}

chains/debug/config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package debug
2+
3+
import (
4+
"fmt"
5+
6+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
7+
"github.com/hyperledger-labs/yui-relayer/core"
8+
)
9+
10+
var _ core.ChainConfig = (*ChainConfig)(nil)
11+
12+
var _ codectypes.UnpackInterfacesMessage = (*ChainConfig)(nil)
13+
14+
func (cfg *ChainConfig) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
15+
if cfg == nil {
16+
return nil
17+
}
18+
if err := unpacker.UnpackAny(cfg.OriginChain, new(core.ChainConfig)); err != nil {
19+
return err
20+
}
21+
return nil
22+
}
23+
24+
func (c ChainConfig) Build() (core.Chain, error) {
25+
if c.OriginChain == nil {
26+
return nil, fmt.Errorf("OriginChain must be set")
27+
}
28+
if c.OriginChain.GetCachedValue() == nil {
29+
return nil, fmt.Errorf("OriginChain.GetCachedValue() must be set")
30+
}
31+
32+
originChain, err := c.OriginChain.GetCachedValue().(core.ChainConfig).Build()
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
return &Chain{
38+
config: c,
39+
OriginChain: originChain,
40+
}, nil
41+
}
42+
43+
func (c ChainConfig) Validate() error {
44+
return nil
45+
}

0 commit comments

Comments
 (0)