-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from keep-network/keep-inspection-scripts
Keep inspection scripts Gathering scripts from different repos to one single place for inspecting different keep network applications and their behaviour on Ropsten / Mainnet.
- Loading branch information
Showing
5 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const truffleContract = require("@truffle/contract") | ||
const KeepRandomBeaconOperatorJson = require("@keep-network/keep-core/artifacts/KeepRandomBeaconOperator.json") | ||
|
||
const contractHelper = require("./lib/contract-helper") | ||
|
||
module.exports = async function() { | ||
try { | ||
const deploymentBlock = await contractHelper.getDeploymentBlockNumber(KeepRandomBeaconOperatorJson, web3) | ||
|
||
const KeepRandomBeaconOperator = truffleContract(KeepRandomBeaconOperatorJson) | ||
KeepRandomBeaconOperator.setProvider(web3.currentProvider) | ||
|
||
const keepRandomBeaconOperator = await KeepRandomBeaconOperator.deployed() | ||
|
||
const numberOfGroups = await keepRandomBeaconOperator.numberOfGroups() | ||
const entryRequestedEvents = await keepRandomBeaconOperator.getPastEvents( | ||
"RelayEntryRequested", | ||
{ | ||
fromBlock: deploymentBlock, | ||
toBlock: "latest", | ||
} | ||
) | ||
const entrySubmittedEvents = await keepRandomBeaconOperator.getPastEvents( | ||
"RelayEntrySubmitted", | ||
{ | ||
fromBlock: deploymentBlock, | ||
toBlock: "latest", | ||
} | ||
) | ||
const timeoutEvents = await keepRandomBeaconOperator.getPastEvents( | ||
"RelayEntryTimeoutReported", | ||
{ | ||
fromBlock: deploymentBlock, | ||
toBlock: "latest", | ||
} | ||
) | ||
|
||
console.log(`Number of groups: ${numberOfGroups}`) | ||
console.log(`Relay entries requested: ${entryRequestedEvents.length}`) | ||
console.log(`Relay entries submitted: ${entrySubmittedEvents.length}`) | ||
console.log(`Number of timed-out entries: ${timeoutEvents.length}`) | ||
console.log(``) | ||
|
||
const dkgSubmittedEvents = (await keepRandomBeaconOperator.getPastEvents( | ||
"DkgResultSubmittedEvent", | ||
{ | ||
fromBlock: deploymentBlock, | ||
toBlock: "latest", | ||
} | ||
)) | ||
|
||
const allOperators = new Set() | ||
|
||
for (i = 0; i < numberOfGroups; i++) { | ||
const groupPubKey = await keepRandomBeaconOperator.getGroupPublicKey(i) | ||
const groupMembers = await keepRandomBeaconOperator.getGroupMembers(groupPubKey) | ||
|
||
const uniqueMembers = new Set() | ||
groupMembers.forEach((member) => { | ||
uniqueMembers.add(member) | ||
allOperators.add(member) | ||
}) | ||
|
||
const dkgSubmittedEvent = dkgSubmittedEvents.find((event) => { | ||
return event.returnValues.groupPubKey == groupPubKey | ||
}) | ||
|
||
const {memberIndex, misbehaved} = dkgSubmittedEvent.returnValues | ||
|
||
console.log(`Group ${groupPubKey}:`) | ||
console.log(` - has index ${i}`) | ||
console.log(` - has ${groupMembers.length} members`) | ||
console.log(` - its DKG result was submitted by member ${memberIndex}`) | ||
console.log(` - misbehaved members bytes: ${misbehaved}`) | ||
console.log(` - has ${uniqueMembers.size} unique members`) | ||
console.log(``) | ||
} | ||
|
||
console.log(`There are ${allOperators.size} unique operators in all groups`) | ||
|
||
process.exit() | ||
} catch (error) { | ||
console.log(error) | ||
process.exit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const truffleContract = require("@truffle/contract") | ||
|
||
const BondedECDSAKeepFactoryJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeepFactory.json") | ||
const BondedECDSAKeepJson = require("@keep-network/keep-ecdsa/artifacts/BondedECDSAKeep.json") | ||
|
||
module.exports = async function () { | ||
try { | ||
const BondedECDSAKeepFactory = truffleContract(BondedECDSAKeepFactoryJson) | ||
BondedECDSAKeepFactory.setProvider(web3.currentProvider) | ||
const BondedECDSAKeep = truffleContract(BondedECDSAKeepJson) | ||
BondedECDSAKeep.setProvider(web3.currentProvider) | ||
|
||
const factory = await BondedECDSAKeepFactory.deployed() | ||
|
||
const keepCount = await factory.getKeepCount() | ||
console.log(`created keeps count: ${keepCount}`) | ||
|
||
const allOperators = new Set() | ||
const goodOperators = new Set() | ||
|
||
for (i = 0; i < keepCount; i++) { | ||
const keepAddress = await callWithRetry(() => factory.getKeepAtIndex(i)) | ||
const keep = await BondedECDSAKeep.at(keepAddress) | ||
const keepPublicKey = await callWithRetry(() => keep.publicKey()) | ||
const members = await callWithRetry(() => keep.getMembers()) | ||
const isActive = await callWithRetry(() => keep.isActive()) | ||
const bond = await callWithRetry(()=> keep.checkBondAmount()) | ||
|
||
console.log(`keep address: ${keepAddress}`) | ||
console.log(`keep index: ${i}`) | ||
console.log(`pubkey: ${keepPublicKey}`) | ||
console.log(`members: ${members}`) | ||
console.log(`isActive: ${isActive}`) | ||
console.log(`bond [wei]: ${bond}`) | ||
console.log(`bond [eth]: ${web3.utils.fromWei(bond)}`) | ||
|
||
members.forEach((member) => allOperators.add(member)) | ||
if (keepPublicKey) { | ||
members.forEach((member) => goodOperators.add(member)) | ||
} | ||
|
||
console.log(``) | ||
} | ||
|
||
// if the operator is a member of at least one keep and that operator | ||
// is NOT a member of at least one keep which successfully generated | ||
// a public key, this operator is here | ||
let potentiallyBadOperators = new Set(allOperators) | ||
for (let goodOperator of goodOperators) { | ||
potentiallyBadOperators.delete(goodOperator) | ||
} | ||
console.log(`potentially bad operators = ${new Array(...potentiallyBadOperators).join(', ')}`) | ||
|
||
process.exit() | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
|
||
async function callWithRetry(fn) { | ||
try { | ||
return await fn() | ||
} catch (error) { | ||
console.log(`Error ${error} occurred; retrying...`) | ||
return await fn() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const DepositJson = require("@keep-network/tbtc/artifacts/Deposit.json") | ||
const DepositFactoryJson = require("@keep-network/tbtc/artifacts/DepositFactory.json") | ||
|
||
const truffleContract = require("@truffle/contract") | ||
const contractHelper = require("./lib/contract-helper") | ||
|
||
module.exports = async function() { | ||
try { | ||
const factoryDeploymentBlock = await contractHelper.getDeploymentBlockNumber(DepositFactoryJson, web3) | ||
|
||
const DepositFactory = truffleContract(DepositFactoryJson) | ||
DepositFactory.setProvider(web3.currentProvider) | ||
const Deposit = truffleContract(DepositJson) | ||
Deposit.setProvider(web3.currentProvider) | ||
|
||
const factory = await DepositFactory.deployed() | ||
|
||
const depositCreatedEvents = await factory.getPastEvents( | ||
"DepositCloneCreated", | ||
{ | ||
fromBlock: factoryDeploymentBlock, | ||
toBlock: "latest", | ||
} | ||
) | ||
|
||
console.log(`Number of created deposits: ${depositCreatedEvents.length} \n`) | ||
|
||
const depositAddresses = [] | ||
depositCreatedEvents.forEach((event) => | ||
depositAddresses.push(event.args.depositCloneAddress) | ||
) | ||
|
||
for (i = 0; i < depositAddresses.length; i++) { | ||
const deposit = await Deposit.at(depositAddresses[i]) | ||
const state = await deposit.currentState() | ||
let stateString = "" | ||
switch(state.toString()) { | ||
case "0": stateString = "START"; break | ||
case "1": stateString = "AWAITING_SIGNER_SETUP"; break | ||
case "2": stateString = "AWAITING_BTC_FUNDING_PROOF"; break | ||
case "3": stateString = "FAILED_SETUP"; break | ||
case "4": stateString = "ACTIVE"; break | ||
case "5": stateString = "AWAITING_WITHDRAWAL_SIGNATURE"; break | ||
case "6": stateString = "AWAITING_WITHDRAWAL_PROOF"; break | ||
case "7": stateString = "REDEEMED"; break | ||
case "8": stateString = "COURTESY_CALL"; break | ||
case "9": stateString = "FRAUD_LIQUIDATION_IN_PROGRESS"; break | ||
case "10": stateString = "LIQUIDATION_IN_PROGRESS"; break | ||
case "11": stateString = "LIQUIDATED"; break | ||
default: stateString = "<< UNKNOWN >>"; break | ||
} | ||
const keepAddress = await deposit.keepAddress() | ||
const lotSizeSatoshis = await deposit.lotSizeSatoshis() | ||
const lotSizeTbtc = await deposit.lotSizeTbtc() | ||
|
||
console.log(`deposit address: ${depositAddresses[i]}`) | ||
console.log(`deposit index: ${i}`) | ||
console.log(`deposit state: ${stateString}`) | ||
console.log(`keep address: ${keepAddress}`) | ||
console.log(`lot size [sat]: ${lotSizeSatoshis}`) | ||
console.log(`lot size [tbtc]: ${lotSizeTbtc}`) | ||
|
||
console.log(``) | ||
} | ||
|
||
process.exit() | ||
} catch (error) { | ||
console.log(error) | ||
process.exit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const getDeploymentBlockNumber = async function(contractJSON, web3) { | ||
const networkId = Object.keys(contractJSON.networks)[0] | ||
const transactionHash = contractJSON.networks[networkId].transactionHash | ||
const transaction = await web3.eth.getTransaction(transactionHash) | ||
|
||
return transaction.blockNumber | ||
} | ||
|
||
module.exports = { | ||
getDeploymentBlockNumber: getDeploymentBlockNumber | ||
} |