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

Switch mock proofs to real proofs; debug #5711

Merged
merged 26 commits into from
Mar 7, 2020
Merged

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Feb 27, 2020

closes #5693

@cwgoes
Copy link
Contributor Author

cwgoes commented Feb 27, 2020

The handshake problems can be clearly reproduced now:

go test ./x/ibc/03-connection/keeper/...

@cwgoes
Copy link
Contributor Author

cwgoes commented Feb 27, 2020

I fixed one minor mistake in a test-case.

Right now there are two errors:

--- FAIL: TestKeeperTestSuite (0.41s)
    --- FAIL: TestKeeperTestSuite/TestConnOpenAck (0.06s)
        --- FAIL: TestKeeperTestSuite/TestConnOpenAck/Case_success (0.01s)
            handshake_test.go:204: 
                	Error Trace:	handshake_test.go:204
                	            				suite.go:77
                	Error:      	Received unexpected error:
                	            	self consensus state not found
                	Test:       	TestKeeperTestSuite/TestConnOpenAck/Case_success
                	Messages:   	valid test case 0 failed: success

I tried to fix this with 850e6c3#diff-b1978f573dd726c3b9b0b8bb6f72b7ffR180 but this didn't seem to work.

The other problem is the one we've observed in the handshakes:

    --- FAIL: TestKeeperTestSuite/TestConnOpenConfirm (0.04s)
        --- FAIL: TestKeeperTestSuite/TestConnOpenConfirm/Case_success (0.01s)
            handshake_test.go:255: 
                	Error Trace:	handshake_test.go:255
                	            				suite.go:77
                	Error:      	Received unexpected error:
                	            	
                	            	github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types.ClientState.VerifyConnectionState
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types/client_state.go:160
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper.Keeper.VerifyConnectionState
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/verify.go:59
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper.Keeper.ConnOpenConfirm
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/handshake.go:222
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper_test.(*KeeperTestSuite).TestConnOpenConfirm.func6
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/handshake_test.go:252
                	            	github.com/stretchr/testify/suite.(*Suite).Run.func1
                	            		/home/cwgoes/working/tendermint/go/pkg/mod/github.com/stretchr/testify@v1.5.1/suite/suite.go:77
                	            	connection state verification failed: calculated root hash is invalid: expected [65 202 250 227 28 199 15 88 1 250 16 22 162 221 84 169 188 184 32 27 91 56 153 25 254 153 118 118 37 50 197 22] but got [96 48 99 120 144 155 117 126 20 167 25 162 81 126 86 115 253 133 118 85 75 108 219 45 193 246 196 136 24 26 203 198]
                	Test:       	TestKeeperTestSuite/TestConnOpenConfirm/Case_success
                	Messages:   	valid test case 0 failed: success

This recurs across all of the handshake / verification tests.

x/ibc/03-connection/keeper/handshake_test.go Outdated Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake_test.go Outdated Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake_test.go Outdated Show resolved Hide resolved
x/ibc/types/mock.go Outdated Show resolved Hide resolved
(path.String() == proof.path.String()) &&
bytes.Equal(value, proof.value) {
return nil
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block (from golint)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

@cwgoes cwgoes changed the title Debug mock proofs Switch mock proofs to real proofs; debug Feb 27, 2020
@cwgoes
Copy link
Contributor Author

cwgoes commented Feb 27, 2020

I have altered the test-cases to return the consensus heights they should be using, no luck yet, I suspect there is a single underlying problem that we need to isolate.

go test ./x/ibc/03-connection/keeper/... -run TestKeeperTestSuite/TestConnOpenTry
--- FAIL: TestKeeperTestSuite (0.06s)
    --- FAIL: TestKeeperTestSuite/TestConnOpenTry (0.06s)
        --- FAIL: TestKeeperTestSuite/TestConnOpenTry/Case_success (0.01s)
            handshake_test.go:125: 
                	Error Trace:	handshake_test.go:125
                	            				suite.go:77
                	Error:      	Received unexpected error:
                	            	
                	            	github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types.ClientState.VerifyConnectionState
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types/client_state.go:160
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper.Keeper.VerifyConnectionState
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/verify.go:59
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper.Keeper.ConnOpenTry
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/handshake.go:82
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper_test.(*KeeperTestSuite).TestConnOpenTry.func8
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/handshake_test.go:118
                	            	github.com/stretchr/testify/suite.(*Suite).Run.func1
                	            		/home/cwgoes/working/tendermint/go/pkg/mod/github.com/stretchr/testify@v1.5.1/suite/suite.go:77
                	            	connection state verification failed: calculated root hash is invalid: expected [65 202 250 227 28 199 15 88 1 250 16 22 162 221 84 169 188 184 32 27 91 56 153 25 254 153 118 118 37 50 197 22] but got [222 160 240 36 202 50 93 224 173 12 40 103 181 198 119 229 212 218 118 71 53 182 161 92 177 58 140 184 151 245 148 127]
                	Test:       	TestKeeperTestSuite/TestConnOpenTry/Case_success
                	Messages:   	valid test case 0 failed with consensus height 3: success
FAIL
FAIL	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper	0.087s
FAIL

I'm also confused by the fact that the expected root hash seems to be constant but the real one changes each time I re-run the tests - is the test-suite supposed to be deterministic?

)

if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg)
suite.Require().NoError(err, "valid test case %d failed with consensus height %d: %s", i, consensusHeight, tc.msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the variable on range scope i in function literal (from scopelint)

} else {
suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg)
suite.Require().Error(err, "invalid test case %d passed with consensus height %d: %s", i, consensusHeight, tc.msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the variable on range scope i in function literal (from scopelint)

x/ibc/03-connection/keeper/handshake_test.go Show resolved Hide resolved
connection.GetCompatibleVersions(), tc.proofInit, tc.proofConsensus,
uint64(proofHeight), uint64(consensusHeight),
connection.GetCompatibleVersions(), proofInit, proofConsensus,
uint64(proofHeight), consensusHeight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary conversion (from unconvert)


// consensusKey := ibctypes.KeyConsensusState(testClientIDB, uint64(proofHeight))
// proofConsensus, consensusHeight := suite.queryProof(consensusKey)
consensusKey := ibctypes.KeyConsensusState(testClientIDB, uint64(consensusHeight))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary conversion (from unconvert)

suite.chainA.GetContext(), testConnectionIDA, tc.version, tc.proofTry, tc.proofConsensus,
uint64(proofHeight), uint64(consensusHeight),
suite.chainA.GetContext(), testConnectionIDA, tc.version, proofTry, proofConsensus,
uint64(proofHeight), consensusHeight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary conversion (from unconvert)

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 2, 2020

Issues fixed in 69cf142:

  • Off-by-one height error (app state is from last commit)
  • verifyClientConsensusState needs to use counterparty client identifier
  • Need two header updates to make counterparty consensus states accurate

Still debugging

  • Mistakes in identiifier handling in ICS 7 (chain ID & client ID are not the same thing)

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 2, 2020

Still some issues with expected consensus state & self consensus state mis-matching.

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 2, 2020

TestConnOpenConfirm and the connection state verification in general now works, no luck on the consensus state verification mismatch yet.

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 2, 2020

To run the ConnOpenTry test (still failing):

go test ./x/ibc/03-connection/keeper/... -run TestKeeperTestSuite/TestConnOpenTry

resulting in

root: {[216 137 244 20 97 87 138 53 114 6 173 141 41 248 245 15 217 3 64 210 56 147 140 117 121 232 178 151 123 196 76 13]} at height 4
path: /ibc/consensusState%2Ftestclientida%2F3
--- FAIL: TestKeeperTestSuite (0.02s)
    --- FAIL: TestKeeperTestSuite/TestConnOpenTry (0.02s)
        --- FAIL: TestKeeperTestSuite/TestConnOpenTry/Case_success (0.01s)
            handshake_test.go:133: 
                	Error Trace:	handshake_test.go:133
                	            				suite.go:77
                	Error:      	Received unexpected error:
                	            	
                	            	github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types.ClientState.VerifyClientConsensusState
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types/client_state.go:132
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper.Keeper.VerifyClientConsensusState
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/verify.go:29
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper.Keeper.ConnOpenTry
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/handshake.go:93
                	            	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper_test.(*KeeperTestSuite).TestConnOpenTry.func8
                	            		/home/cwgoes/working/tendermint/go/src/github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper/handshake_test.go:126
                	            	github.com/stretchr/testify/suite.(*Suite).Run.func1
                	            		/home/cwgoes/working/tendermint/go/pkg/mod/github.com/stretchr/testify@v1.5.1/suite/suite.go:77
                	            	client consensus state verification failed: verifying value: leaf value hash not same: invalid proof
                	Test:       	TestKeeperTestSuite/TestConnOpenTry/Case_success
                	Messages:   	valid test case 0 failed with consensus height 3 and proof height 3: success
FAIL
FAIL	github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper	0.048s

// Create target ctx
ctxTarget := chain.GetContext()

// create client
clientState, err := ibctmtypes.Initialize(client.ClientID, trustingPeriod, ubdPeriod, client.Header)
clientState, err := ibctmtypes.Initialize(chain.ClientID, trustingPeriod, ubdPeriod, client.Header)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so looks like my code caused some confusion here.

I believe I should rename this field to client.ChainID and document clearly that the clientID that other chains store for the given client is the chainID of the client chain for simplicity in the tests.

So TestChainA may have a chainID field called: testchainida.

If TestChainB creates a client for TestChainA, it will give it the clientID testchainida

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's alright too, it was just inconsistent in some places. The key question is why consensus state verification is failing though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm working through the test cases now, and I'm getting a failure on Connection state verification before i hit consensus state verification

Did you comment out the connection state issue to hit consensus state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it works for me, can you provide replication instructions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i meant on my own branch that reverts your identifier issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, great! Feel free to revise then.

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 3, 2020

Step 1: Get these tests working. Step 2: Test relayer again, get it working.

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 4, 2020

All the handshake tests pass locally for me & the changes make sense, left a comment about a height offset we need to remember to deal with correctly in the relayer. Hopefully we can turn these into more end-to-end tests in the future, but for now fixing the verification tests and moving back to the relayer to get the connection handshake working there makes sense to me as an order of priorities.

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Minor cleanup comments

client.Header = nextHeader(client)

/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment?

invalidProof struct{}
)

func (validProof) GetCommitmentType() commitment.Type {
return commitment.Merkle
}

func (validProof) VerifyMembership(
func (proof validProof) VerifyMembership(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we still using these proofs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't be, maybe we can delete them altogether?

(path.String() == proof.path.String()) &&
bytes.Equal(value, proof.value) {
return nil
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

@@ -105,12 +105,15 @@ func (cs ClientState) IsFrozen() bool {
// Tendermint client stored on the target machine.
func (cs ClientState) VerifyClientConsensusState(
cdc *codec.Codec,
provingRoot commitment.RootI,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the counterparty commitment root? add comment

@@ -156,6 +159,8 @@ func (cs ClientState) VerifyConnectionState(
return err
}

fmt.Printf("verify against consensus state %v\n", consensusState)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Printf("verify against consensus state %v\n", consensusState)

x/ibc/types/mock.go Outdated Show resolved Hide resolved
x/ibc/types/mock.go Show resolved Hide resolved
@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 5, 2020

Thanks @fedekunze!

Tested locally, everything except ICS 04 tests passes for me now. Those look like they also need to be updated to use queryProof and do the correct connection initialisation, channel initialisation, and client update logic. Up to you @AdityaSripal as to whether you want to debug those now or try to get the connection handshake working in the relayer first; I think either is fine.

Also, it would be nice to share code between the ICS 03 and ICS 04 tests somehow, there seems to be a lot of duplicate logic in the test setup that we have to edit in multiple places right now.

Timestamp: ctx.BlockTime(),
Height: height,
// FIXME: Currently commented out due to time normalisation issues.
//Timestamp: histInfo.Header.Time,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to get fixed in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to figure it out, some sort of normalisation (maybe in Tendermint?).

We should either fix it or open an issue to track it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What feature/guarantee/check are we missing by not having this timestamp?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK (can't approve since I created the PR) modulo comments & #5761. Thanks @AdityaSripal!

Timestamp: ctx.BlockTime(),
Height: height,
// FIXME: Currently commented out due to time normalisation issues.
//Timestamp: histInfo.Header.Time,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to figure it out, some sort of normalisation (maybe in Tendermint?).

We should either fix it or open an issue to track it.

x/ibc/03-connection/keeper/handshake_test.go Show resolved Hide resolved
invalidProof struct{}
)

func (validProof) GetCommitmentType() commitment.Type {
return commitment.Merkle
}

func (validProof) VerifyMembership(
func (proof validProof) VerifyMembership(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't be, maybe we can delete them altogether?

@jackzampolin
Copy link
Member

Failing sim and proto checks. Lets get those cleaned up before we merge this?

@jackzampolin
Copy link
Member

Failing simulation:

Simulation complete; Final height (blocks): 51, final time (seconds): 3861-10-29 02:54:35 -0800 PST, operations ran: 14700
{
 "bank": {
  "multisend": {
   "ok": 151
  },
  "no-operation": {
   "failure": 99
  },
  "send": {
   "ok": 1449
  }
 },
 "begin_block": {
  "evidence": {
   "ok": 3
  },
  "signing": {
   "missed": 523,
   "signed": 2588
  }
 },
 "distribution": {
  "fund_community_pool": {
   "ok": 690
  },
  "no-operation": {
   "failure": 917
  },
  "set_withdraw_address": {
   "ok": 736
  },
  "withdraw_delegator_reward": {
   "ok": 375
  },
  "withdraw_validator_commission": {
   "ok": 165
  }
 },
 "end_block": {
  "validator_updates": {
   "added": 189,
   "kicked": 189,
   "updated": 379
  }
 },
 "gov": {
  "deposit": {
   "ok": 290
  },
  "no-operation": {
   "failure": 1874
  },
  "submit_proposal": {
   "ok": 185
  },
  "vote": {
   "ok": 277
  }
 },
 "slashing": {
  "no-operation": {
   "failure": 1481
  },
  "unjail": {
   "failure": 1
  }
 },
 "staking": {
  "begin_redelegate": {
   "ok": 1410
  },
  "begin_unbonding": {
   "ok": 1564
  },
  "create_validator": {
   "ok": 978
  },
  "delegate": {
   "ok": 1469
  },
  "edit_validator": {
   "ok": 35
  },
  "no-operation": {
   "failure": 554
  }
 }
}
exporting app state...
--- FAIL: TestAppImportExport (164.12s)
    sim_test.go:110: 
        	Error Trace:	sim_test.go:110
        	Error:      	Received unexpected error:
        	            	open /tmp/sim-logs-323511574/sim_state-491163361.json: no such file or directory
        	Test:       	TestAppImportExport
FAIL

@jackzampolin jackzampolin merged commit 1818d98 into ibc-alpha Mar 7, 2020
@jackzampolin jackzampolin deleted the cwgoes/debug-proofs branch March 7, 2020 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants