This repository has been archived by the owner on Dec 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfixDupes.js
124 lines (112 loc) · 3.49 KB
/
fixDupes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { Client } = require('@elastic/elasticsearch')
const eosjs = require('eosjs');
const JsonRpc = eosjs.JsonRpc;
const fetch = require("node-fetch"); // node only; not needed in browsers
//const nodeUrl = 'https://testnet.telos.caleos.io';
const nodeUrl = 'https://telos.caleos.io';
const ACTION_INDEX_PATTERN = 'telos-mainnet-action-*';
const rpc = new JsonRpc(nodeUrl, { fetch });
const client = new Client({
node: 'http://localhost:9200',
auth: {
username: 'elastic',
password: 'password'
}
})
async function run () {
let blockMap = {};
const query = {
"aggs": {
"duplicateCount": {
"terms": {
"field": "trx_id",
"min_doc_count": 2
},
"aggs": {
"duplicateDocuments": {
"top_hits": {}
}
}
}
}
};
/*
{
"size": 0,
"aggs": {
"my_buckets": {
"composite": {
"sources": [
{ "product": { "terms": { "field": "product" } } }
]
}
}
}
}
*/
const compQuery = {
"size": 0,
"aggs": {
"duplicateCount": {
"sources": {
"trx": {
"field": "trx_id",
"min_doc_count": 2
}
},
"aggs": {
"duplicateDocuments": {
"top_hits": {}
}
}
}
}
}
const result = await client.search({
index: ACTION_INDEX_PATTERN,
size: 0,
body: query
})
let buckets = result.body.aggregations.duplicateCount.buckets;
let count = 0;
for (let bucket of buckets) {
console.log(`${++count} ========== ${bucket.key}`);
const hits = bucket.duplicateDocuments.hits.hits;
for (let hit of hits) {
let doc = hit._source;
const blockResult = await rpc.get_block(doc.block_num);
blockMap[doc.block_id] = {blockNumber: doc.block_num, wasForked: (blockResult.id !== doc.block_id)};
console.log(`${doc.block_num} -- ${doc.block_id} ${doc.rec} ${doc.act.account}::${doc.act.name} ${blockMap[doc.block_id].wasForked ? "FORKED" : "VALID"}`);
}
}
for (let blockId in blockMap) {
if (!blockMap[blockId].wasForked) {
continue;
}
const searchBody = {
query: {bool: {must: [{term: {block_id: blockId}}]}}
};
console.log("Deleting actions from blockId: " + blockId);
let result = await client.deleteByQuery({
index: ACTION_INDEX_PATTERN,
refresh: true,
body: searchBody
});
console.log("Deleted: " + result.body.deleted);
}
/*
const searchBody = {
query: {bool: {must: [{term: {block_id: targetBlockId}}]}}
};
// remove deltas
await new Promise<void>((resolve) => {
setTimeout(async () => {
const dbqResult = await this.client.deleteByQuery({
index: this.chain + '-delta-' + this.conf.settings.index_version + '-*',
refresh: true,
body: searchBody
});
*/
//console.log(JSON.stringify(blockMap, null, 4));
}
run().catch(console.log);