signer: fix clique interoperability between geth and clef

This commit is contained in:
Martin Holst Swende 2019-02-06 13:31:47 +01:00
parent 73e013fe51
commit 65ab280e57
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 14 additions and 6 deletions

View file

@ -44,6 +44,9 @@ function testClique(){
var a = accts[0] var a = accts[0]
var r = debug.testSignCliqueBlock(a, 0); // Sign genesis var r = debug.testSignCliqueBlock(a, 0); // Sign genesis
console.log("signing response", r) console.log("signing response", r)
if( a != r){
throw new Error("Requested signing by "+a+ " but got sealer "+r)
}
} }
} }

View file

@ -1490,11 +1490,9 @@ func (api *PublicDebugAPI) TestSignCliqueBlock(ctx context.Context, address comm
return common.Address{}, fmt.Errorf("block #%d not found", number) return common.Address{}, fmt.Errorf("block #%d not found", number)
} }
header := block.Header() header := block.Header()
header.Extra = make([]byte, 65) header.Extra = make([]byte, 32+65)
encoded, err := rlp.EncodeToBytes(header) encoded := clique.CliqueRLP(header)
if err != nil {
return common.Address{}, err
}
// Look up the wallet containing the requested signer // Look up the wallet containing the requested signer
account := accounts.Account{Address: address} account := accounts.Account{Address: address}
wallet, err := api.b.AccountManager().Find(account) wallet, err := api.b.AccountManager().Find(account)

View file

@ -140,7 +140,7 @@ func (api *SignerAPI) sign(addr common.MixedcaseAddress, req *SignDataRequest, l
return nil, err return nil, err
} }
// Sign the data with the wallet // Sign the data with the wallet
signature, err := wallet.SignDataWithPassphrase(account, res.Password, req.ContentType, req.Hash) signature, err := wallet.SignDataWithPassphrase(account, res.Password, req.ContentType, req.Rawdata)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -214,6 +214,13 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
if err := rlp.DecodeBytes(cliqueData, header); err != nil { if err := rlp.DecodeBytes(cliqueData, header); err != nil {
return nil, useLegacyV, err return nil, useLegacyV, err
} }
// The incoming clique header is already truncated, sent to us with a extradata already shortened
if len(header.Extra) < 65 {
// Need to add it back, to get a suitable length for hashing
newExtra := make([]byte, len(header.Extra)+65)
copy(newExtra, header.Extra)
header.Extra = newExtra
}
// Get back the rlp data, encoded by us // Get back the rlp data, encoded by us
sighash, cliqueRlp, err := cliqueHeaderHashAndRlp(header) sighash, cliqueRlp, err := cliqueHeaderHashAndRlp(header)
if err != nil { if err != nil {