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

feat(apps/whale-api): add updatemasternode indexer #1869

Merged
merged 81 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
b4df405
Add updateMasternode rpc (WIP)
marktanrj Nov 1, 2022
80cee4a
Add test cases
marktanrj Nov 2, 2022
cc0f828
Undo update config that was accidentally committed
marktanrj Nov 2, 2022
b995da1
Update testcases
marktanrj Nov 15, 2022
27721d8
Merge branch 'main' into marktanrj/updatemasternode-rpc-typing
marktanrj Nov 15, 2022
bc30eb9
Update image version
marktanrj Nov 16, 2022
bb06945
Update image version
marktanrj Nov 16, 2022
1673e35
add dftx (WIP)
marktanrj Nov 18, 2022
9fa64e0
Add mapping
imkven Nov 18, 2022
0ed853b
WIP
imkven Nov 19, 2022
30a9b3a
Resolve conflict
marktanrj Nov 20, 2022
5b8b3bc
Update image version
marktanrj Nov 21, 2022
e648101
Remove redundant code
marktanrj Nov 21, 2022
68674dd
Add transaction builder tests (WIP)
marktanrj Nov 21, 2022
67d6e5e
Fix format
marktanrj Nov 21, 2022
642b411
Fix format bug
marktanrj Nov 21, 2022
e4a9e87
Add tests for updating operator and reward address
marktanrj Nov 21, 2022
7810449
Add tests
marktanrj Nov 22, 2022
916df3d
Update image version
marktanrj Nov 22, 2022
3cc79ce
Update tests
marktanrj Nov 22, 2022
c7f541f
Update test and dftx for removing reward address
marktanrj Nov 22, 2022
da84f9c
Minor edit
marktanrj Nov 22, 2022
02e0cf4
Add tests for transaction builder
marktanrj Nov 22, 2022
8b9bc7a
Fix mistakes in comments
marktanrj Nov 22, 2022
860c373
Fix buggy code for UpdateMasternodeData
marktanrj Nov 22, 2022
b5c7fd7
Minor changes
marktanrj Nov 22, 2022
4fd412f
Add jellyfish transaction tests
marktanrj Nov 22, 2022
66554f7
feat(v3): bump to grandcentral and use `master-1d169a751` (#1841)
shohamc1 Nov 21, 2022
fbbd44f
chore(jellyfish-api-core): Change assert order in `getMiningInfo.test…
shohamc1 Nov 22, 2022
24ca435
feat(jellyfish-api-core): defid v3 poolpair/poolswap internal changes…
shohamc1 Nov 22, 2022
65b03f3
fix(jellyfish-api-core): update testPoolSwap arguments (#1856)
shohamc1 Nov 22, 2022
e469233
Undo update config that was accidentally committed
marktanrj Nov 2, 2022
aa478b5
Update image version
marktanrj Nov 16, 2022
3eb0a95
Undo rebase mess up
marktanrj Nov 22, 2022
408b4ea
Merge main
marktanrj Nov 22, 2022
8c3d7b6
Merge main
marktanrj Nov 22, 2022
6defd80
Add more tests
marktanrj Nov 22, 2022
8b655dc
Merge remote-tracking branch 'origin/marktanrj/updatemasternode-rpc-t…
imkven Nov 23, 2022
f44e81b
Add updatemasternode indexer
imkven Nov 23, 2022
9b15245
Add invalidate for update masternode
imkven Nov 23, 2022
5964841
Update tests
imkven Nov 24, 2022
e342f76
Update update.masternode.spec.ts
imkven Nov 24, 2022
18699e9
Update update.masternode.spec.ts
imkven Nov 24, 2022
bc161a9
Update tests
marktanrj Nov 24, 2022
b6faef6
Update update.masternode.spec.ts
imkven Nov 24, 2022
a18d7b5
Merge branch 'marktanrj/updatemasternode-dftx' into kvenho/updatemast…
imkven Nov 24, 2022
3a59788
Update update.masternode.spec.ts
imkven Nov 24, 2022
66200ce
Update packages/jellyfish-api-core/src/category/masternode.ts
infinia-yzl Nov 25, 2022
c3f2e7b
Update docs/node/CATEGORIES/11-masternode.md
infinia-yzl Nov 25, 2022
11c9e05
Add updatemasternode rpc
marktanrj Nov 25, 2022
08c0420
Attempt to fix update owner address in masternode test (WIP)
marktanrj Nov 25, 2022
e0de0f4
Update
marktanrj Nov 29, 2022
ffbfd9d
Fix update owner address test
marktanrj Nov 29, 2022
331c9b9
Merge branch 'marktanrj/updatemasternode-dftx' into kvenho/updatemast…
imkven Nov 30, 2022
33fe966
Update tests
marktanrj Nov 30, 2022
0e59f91
Merge main
marktanrj Nov 30, 2022
75cfbb9
Update tests to use object assertion
marktanrj Nov 30, 2022
b55852e
Minor refactor and fix for test
marktanrj Nov 30, 2022
8d2f170
Add tests
marktanrj Nov 30, 2022
d130008
Add test for createDeFiTx
marktanrj Nov 30, 2022
4200566
Merge branch 'marktanrj/updatemasternode-dftx' into kvenho/updatemast…
imkven Dec 1, 2022
444d86e
Update vout utxo amounts to be more deterministic
marktanrj Dec 1, 2022
0574935
Resolve PR comments
marktanrj Dec 1, 2022
71da6aa
Remove transaction builder code and shift into separate branch
marktanrj Dec 1, 2022
d4d7736
Merge branch 'main' into marktanrj/updatemasternode-dftx
marktanrj Dec 1, 2022
f1ad1a5
Merge branch 'marktanrj/updatemasternode-dftx' into kvenho/updatemast…
marktanrj Dec 1, 2022
722a679
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
fuxingloh Dec 1, 2022
3dcc4a3
Fix regex warnings
shohamc1 Dec 1, 2022
d5c83a5
Only check for lowercase hex characters
shohamc1 Dec 1, 2022
3538564
Remove indexStats and mapTimelockStats
imkven Dec 2, 2022
c545463
Remove invalidateBlockStart
imkven Dec 2, 2022
0b13304
Fix update too much
imkven Dec 2, 2022
349e947
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
imkven Dec 2, 2022
3def4b0
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
imkven Dec 5, 2022
06d60ec
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
imkven Dec 5, 2022
8bbf2ea
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
imkven Dec 8, 2022
0477441
Update apps/whale-api/src/module.indexer/model/dftx/update.masternode.ts
Dec 12, 2022
ee7b350
Update apps/whale-api/src/module.indexer/model/dftx/update.masternode.ts
Dec 12, 2022
0431c1b
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
helloscoopa Dec 12, 2022
faf5589
Merge branch 'main' into kvenho/updatemasternode-whale-indexer
fuxingloh Dec 12, 2022
5dbc55f
chore(whale-api): optimize UpdateMasternode to run without modifying …
fuxingloh Dec 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/whale-api/src/module.indexer/model/dftx.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SetOracleDataIndexer } from './dftx/set.oracle.data'
import { SetOracleDataIntervalIndexer } from './dftx/set.oracle.data.interval'
import { CreateMasternodeIndexer } from './dftx/create.masternode'
import { ResignMasternodeIndexer } from './dftx/resign.masternode'
import { UpdateMasternodeIndexer } from './dftx/update.masternode'
import { Injectable, Logger } from '@nestjs/common'
import { DfTxIndexer, DfTxTransaction } from './dftx/_abstract'
import { PoolSwapIndexer } from './dftx/pool.swap'
Expand All @@ -30,6 +31,7 @@ export class MainDfTxIndexer extends Indexer {
setOracleDataInterval: SetOracleDataIntervalIndexer,
createMasternode: CreateMasternodeIndexer,
resignMasternode: ResignMasternodeIndexer,
updateMasternode: UpdateMasternodeIndexer,
poolSwapIndexer: PoolSwapIndexer,
compositeSwapIndexer: CompositeSwapIndexer,
poolSwapIntervalIndexer: PoolSwapAggregatedIndexer,
Expand All @@ -45,6 +47,7 @@ export class MainDfTxIndexer extends Indexer {
setOracleDataInterval,
createMasternode,
resignMasternode,
updateMasternode,
poolSwapIndexer,
compositeSwapIndexer,
poolSwapIntervalIndexer,
Expand Down
2 changes: 2 additions & 0 deletions apps/whale-api/src/module.indexer/model/dftx/_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SetOracleDataIndexer } from './set.oracle.data'
import { SetOracleDataIntervalIndexer } from './set.oracle.data.interval'
import { CreateMasternodeIndexer } from './create.masternode'
import { ResignMasternodeIndexer } from './resign.masternode'
import { UpdateMasternodeIndexer } from './update.masternode'
import { NetworkName } from '@defichain/jellyfish-network'
import { ConfigService } from '@nestjs/config'
import { PoolSwapIndexer } from './pool.swap'
Expand All @@ -23,6 +24,7 @@ const indexers = [
UpdateOracleIndexer,
CreateMasternodeIndexer,
ResignMasternodeIndexer,
UpdateMasternodeIndexer,
PoolSwapIndexer,
PoolSwapAggregatedIndexer,
CompositeSwapIndexer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ describe('create masternode (pre eunos paya)', () => {
expect(masternode?.creationHeight).toStrictEqual(masternodeRPCInfo.creationHeight)
expect(masternode?.resignHeight).toStrictEqual(masternodeRPCInfo.resignHeight)
expect(masternode?.mintedBlocks).toStrictEqual(masternodeRPCInfo.mintedBlocks)
expect(masternode?.updateRecords).toStrictEqual([{
height: 103,
ownerAddress: masternodeRPCInfo.ownerAuthAddress,
operatorAddress: masternodeRPCInfo.operatorAuthAddress
}])
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class CreateMasternodeIndexer extends DfTxIndexer<CreateMasternode> {
mintedBlocks: 0,
timelock: data.timelock ?? 0,
block: { hash: block.hash, height: block.height, medianTime: block.mediantime, time: block.time },
collateral: txn.vout[1].value.toFixed(8)
collateral: txn.vout[1].value.toFixed(8),
updateRecords: [{ height: block.height, ownerAddress, operatorAddress }]
})

await this.indexStats(block, data, txn.vout[1].value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
import { createTestingApp, DelayedEunosPayaTestContainer, invalidateFromHeight, stopTestingApp, waitForIndexedHeight } from '../../../e2e.module'
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
import { RegTest } from '@defichain/jellyfish-network'
import { P2WPKH } from '@defichain/jellyfish-address'
import { MasternodeMapper } from '../../../module.model/masternode'
import { MasternodeStatsMapper } from '../../../module.model/masternode.stats'

describe('Update masternode', () => {
const container = new DelayedEunosPayaTestContainer()
let app: NestFastifyApplication
let client: JsonRpcClient
let masternodeId: string
let ownerAddress: string

beforeAll(async () => {
await container.start()
await container.waitForWalletCoinbaseMaturity()

app = await createTestingApp(container)
client = new JsonRpcClient(await container.getCachedRpcUrl())

await container.generate(1)

ownerAddress = await client.wallet.getNewAddress()
masternodeId = await client.masternode.createMasternode(ownerAddress)
await container.generate(20)

const height = await client.blockchain.getBlockCount()
// enable updating
await client.masternode.setGov({
ATTRIBUTES: {
'v0/params/feature/mn-setowneraddress': 'true',
'v0/params/feature/mn-setoperatoraddress': 'true',
'v0/params/feature/mn-setrewardaddress': 'true'
}
})
await container.generate(70)
await waitForIndexedHeight(app, height)
})

afterAll(async () => {
await stopTestingApp(container, app)
})

it('should index update operatorAddress, ownerAddress, and rewardAddress in masternode', async () => {
const masternodeMapper = app.get(MasternodeMapper)
const masternode = await masternodeMapper.get(masternodeId)
expect(masternode).not.toStrictEqual(undefined)

const address = await container.getNewAddress('', 'bech32')
const addressDest: P2WPKH = P2WPKH.fromAddress(RegTest, address, P2WPKH)

await client.masternode.updateMasternode(masternodeId, {
operatorAddress: addressDest.utf8String,
rewardAddress: addressDest.utf8String,
ownerAddress: addressDest.utf8String
})

await container.generate(20)
const updateHeight1 = await client.blockchain.getBlockCount()
await container.generate(1)
await waitForIndexedHeight(app, updateHeight1)

const mnResultExpectTransferring = await client.masternode.getMasternode(masternodeId)
expect(mnResultExpectTransferring[masternodeId].state).toStrictEqual('TRANSFERRING')

await container.generate(30)
const updateHeight2 = await client.blockchain.getBlockCount()
await container.generate(1)
await waitForIndexedHeight(app, updateHeight2)

const mnResultExpectPreEnable = await client.masternode.getMasternode(masternodeId)
expect(mnResultExpectPreEnable[masternodeId].state).toStrictEqual('PRE_ENABLED')

await container.generate(20)
const updateHeight3 = await client.blockchain.getBlockCount()
await container.generate(1)
await waitForIndexedHeight(app, updateHeight3)

const mnResult = await client.masternode.getMasternode(masternodeId)
expect(mnResult[masternodeId]).toStrictEqual({
ownerAuthAddress: addressDest.utf8String,
operatorAuthAddress: addressDest.utf8String,
rewardAddress: addressDest.utf8String,
creationHeight: 103,
resignHeight: -1,
resignTx: expect.stringMatching(/[0-9a-f]{64}/),
collateralTx: expect.stringMatching(/[0-9a-f]{64}/),
state: 'ENABLED',
mintedBlocks: 0,
ownerIsMine: true,
operatorIsMine: true,
localMasternode: false,
targetMultipliers: [1, 1]
})

const updatedMasternode = await masternodeMapper.get(masternodeId)
expect(updatedMasternode).toStrictEqual({
id: expect.stringMatching(/[0-9a-f]{64}/),
sort: expect.stringMatching(/[0-9a-f]{72}/),
ownerAddress: addressDest.utf8String,
operatorAddress: addressDest.utf8String,
creationHeight: 193,
resignHeight: -1,
mintedBlocks: 0,
timelock: 0,
block: {
hash: expect.stringMatching(/[0-9a-f]{64}/),
height: 193,
medianTime: expect.any(Number),
time: expect.any(Number)
},
collateral: '2.00000000',
updateRecords: [
{
height: 193,
ownerAddress: addressDest.utf8String,
operatorAddress: addressDest.utf8String
},
{
height: 103,
ownerAddress: ownerAddress,
operatorAddress: ownerAddress
}
]
})

infinia-yzl marked this conversation as resolved.
Show resolved Hide resolved
const masternodeStatsMapper = app.get(MasternodeStatsMapper)
const masternodeStats = await masternodeStatsMapper.getLatest()
expect(masternodeStats?.stats).toStrictEqual({
count: 8,
tvl: '80.00000000',
locked: [
{
weeks: 0,
count: 8,
tvl: '80.00000000'
}
]
})
})

it('should index update remove rewardAddress in masternode', async () => {
const gotBlockCount = await client.blockchain.getBlockCount()
await client.masternode.setGov({
ATTRIBUTES: {
'v0/params/feature/mn-setowneraddress': 'true',
'v0/params/feature/mn-setoperatoraddress': 'true',
'v0/params/feature/mn-setrewardaddress': 'true'
}
})
await container.generate(70)
await waitForIndexedHeight(app, gotBlockCount)

await client.masternode.updateMasternode(masternodeId, {
rewardAddress: ''
})

await container.generate(1)
const updateAgainHeight = await client.blockchain.getBlockCount()
await container.generate(1)
await waitForIndexedHeight(app, updateAgainHeight)

const gotMasternodeForRewardAgain = await client.masternode.getMasternode(masternodeId)
expect(gotMasternodeForRewardAgain[masternodeId]?.rewardAddress).toStrictEqual('')
})
})

describe('invalidate', () => {
const container = new DelayedEunosPayaTestContainer()
let app: NestFastifyApplication
let client: JsonRpcClient

beforeAll(async () => {
await container.start()
await container.waitForWalletCoinbaseMaturity()

app = await createTestingApp(container)
client = new JsonRpcClient(await container.getCachedRpcUrl())
})

afterAll(async () => {
await stopTestingApp(container, app)
})

it('should update masternode and invalidate', async () => {
await container.generate(1)

const ownerAddress = await client.wallet.getNewAddress()
const masternodeId = await client.masternode.createMasternode(ownerAddress)
await container.generate(20)

const height = await client.blockchain.getBlockCount()
// enable updating
await client.masternode.setGov({
ATTRIBUTES: {
'v0/params/feature/mn-setowneraddress': 'true',
'v0/params/feature/mn-setoperatoraddress': 'true',
'v0/params/feature/mn-setrewardaddress': 'true'
}
})
await container.generate(1)
await waitForIndexedHeight(app, height)

const masternodeMapper = app.get(MasternodeMapper)
const masternode = await masternodeMapper.get(masternodeId)

expect(masternode).not.toStrictEqual(undefined)

const address = await container.getNewAddress('', 'bech32')
const addressDest: P2WPKH = P2WPKH.fromAddress(RegTest, address, P2WPKH)
const addressDestHex = addressDest.utf8String

await client.masternode.updateMasternode(masternodeId, { operatorAddress: addressDestHex })

await container.generate(1)
const updateHeight = await client.blockchain.getBlockCount()
await container.generate(1)
await waitForIndexedHeight(app, updateHeight)

const updateMasternode = await masternodeMapper.get(masternodeId)
expect(updateMasternode?.operatorAddress).toStrictEqual(addressDestHex)
expect(updateMasternode?.updateRecords?.length).toStrictEqual(2)

await invalidateFromHeight(app, container, updateHeight)
await container.generate(2)
await waitForIndexedHeight(app, updateHeight)

{
const invalidatedMasternode = await masternodeMapper.get(masternodeId)
const initialAddressDest: P2WPKH = P2WPKH.fromAddress(RegTest, ownerAddress, P2WPKH)
const initialAddressDestHex = initialAddressDest.utf8String

expect(invalidatedMasternode?.ownerAddress).toStrictEqual(initialAddressDestHex)
expect(invalidatedMasternode?.operatorAddress).toStrictEqual(initialAddressDestHex)
expect(invalidatedMasternode?.updateRecords?.length).toStrictEqual(1)
}
})
})
Loading