Skip to content

Commit

Permalink
5806
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Feb 1, 2024
1 parent 0d391eb commit 4d19698
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/rpc/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,8 @@ static void submitchainlock_help(const JSONRPCRequest& request)
{"signature", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The signature of the ChainLock."},
{"blockHeight", RPCArg::Type::NUM, RPCArg::Optional::NO, "The height of the ChainLock."},
},
RPCResults{},
RPCResult{
RPCResult::Type::NUM, "", "The height of the current best ChainLock"},
RPCExamples{""},
}.Check(request);
}
Expand All @@ -1019,21 +1020,23 @@ static UniValue submitchainlock(const JSONRPCRequest& request)
if (nBlockHeight <= 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height");
}
const LLMQContext& llmq_ctx = EnsureLLMQContext(EnsureAnyNodeContext(request.context));
const int32_t bestCLHeight = llmq_ctx.clhandler->GetBestChainLock().getHeight();
if (nBlockHeight <= bestCLHeight) return bestCLHeight;

CBLSSignature sig;
if (!sig.SetHexStr(request.params[1].get_str(), false) && !sig.SetHexStr(request.params[1].get_str(), true)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid signature format");
}


const LLMQContext& llmq_ctx = EnsureLLMQContext(EnsureAnyNodeContext(request.context));
auto clsig = llmq::CChainLockSig(nBlockHeight, nBlockHash, sig);
if (!llmq_ctx.clhandler->VerifyChainLock(clsig)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid signature");
}

llmq_ctx.clhandler->ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig));
return true;
return llmq_ctx.clhandler->GetBestChainLock().getHeight();
}


Expand Down
5 changes: 4 additions & 1 deletion test/functional/feature_llmq_chainlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def run_test(self):
assert best_0['height'] != best_1['height']
assert best_0['signature'] != best_1['signature']
assert_equal(best_0['known_block'], True)
self.nodes[0].submitchainlock(best_1['blockhash'], best_1['signature'], best_1['height'])
node_height = self.nodes[1].submitchainlock(best_0['blockhash'], best_0['signature'], best_0['height'])
rpc_height = self.nodes[0].submitchainlock(best_1['blockhash'], best_1['signature'], best_1['height'])
assert_equal(best_1['height'], node_height)
assert_equal(best_1['height'], rpc_height)
best_0 = self.nodes[0].getbestchainlock()
assert_equal(best_0['blockhash'], best_1['blockhash'])
assert_equal(best_0['height'], best_1['height'])
Expand Down

0 comments on commit 4d19698

Please sign in to comment.