Skip to content

Add query_txid plugin by leveldb#1906

Closed
bijianing97 wants to merge 1 commit intobitshares:developfrom
bijianing97:master
Closed

Add query_txid plugin by leveldb#1906
bijianing97 wants to merge 1 commit intobitshares:developfrom
bijianing97:master

Conversation

@bijianing97
Copy link
Copy Markdown

With this plugin, you can get transaction structure information through txid.
Features:

  1. Save the transactions information in the irreversible blocks to leveldb.
  2. Save the transactions information in the unconfirmed blocks to the db object trx_entry_object, and then move them to leveldb after being confirmed.
  3. Provide get_transaction_by_txid(db api) to query transaction structure.

Performance:

  1. Leveldb is a lightweight third-party database which does not require additional database processes to be started, just install related dependencies and integrate them.
  2. Track all txids and only need little memory usage.

Dependence:

  1. installLeveldb
    wget https://github.com/google/leveldb/archive/v1.20.tar.gz
    tar xvf v1.20.tar.gz
    rm -f v1.20.tar.gz
    cd leveldb-1.20
    make
    sudo cp -r out-static/lib* out-shared/lib* "/usr/local/lib"
    cd include
    sudo cp -r leveldb /usr/local/include
    sudo ldconfig
    
  2. install snappy
    git clone https://github.com/google/snappy.git
    cd snappy
    mkdir build
    cd build && cmake ../ 
    sudo make install
    

More:
https://docs.gxchain.org/zh/advanced/plugin_txid.html

Step:

  1. Compile the new change
    git submodule update --init --recursive
    cmake .
    make
    
  2. Start the witness with plugin
     ./witness_node --plugins "witness account_history query_txid"
    
  3. Query the transaction by txid
curl --data '{
    "jsonrpc": "2.0",
        "method": "call",
        "params": [0, "get_transaction_by_txid", ["c4cb33ac91253147f5a0c426c1cb62fe8185ddb5"]],
        "id": 1
}' 127.0.0.1:28090 | json_pp

Example:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1111  100   948  100   163  67641  11630 --:--:-- --:--:-- --:--:-- 72923
{
   "result" : {
      "ref_block_prefix" : 93791064,
      "operation_results" : [
         [
            0,
            {}
         ]
      ],
      "operations" : [
         [
            6,
            {
               "fee" : {
                  "asset_id" : "1.3.0",
                  "amount" : 2017968
               },
               "account" : "1.2.22517",
               "active" : {
                  "weight_threshold" : 1,
                  "address_auths" : [],
                  "account_auths" : [],
                  "key_auths" : [
                     [
                        "BTS7piPcCkNano63VbgQq7RJh3xx5n61yWEC7PLrJ2vNVxGvZ2KYS",
                        1
                     ]
                  ]
               },
               "owner" : {
                  "key_auths" : [
                     [
                        "BTS7piPcCkNano63VbgQq7RJh3xx5n61yWEC7PLrJ2vNVxGvZ2KYS",
                        1
                     ]
                  ],
                  "weight_threshold" : 1,
                  "address_auths" : [],
                  "account_auths" : []
               },
               "extensions" : {},
               "new_options" : {
                  "memo_key" : "BTS7piPcCkNano63VbgQq7RJh3xx5n61yWEC7PLrJ2vNVxGvZ2KYS",
                  "extensions" : [],
                  "num_committee" : 0,
                  "voting_account" : "1.2.5",
                  "votes" : [
                     "1:22",
                     "1:24",
                     "1:25",
                     "1:27",
                     "1:28",
                     "1:29",
                     "1:30",
                     "1:32",
                     "1:33",
                     "1:36",
                     "1:38"
                  ],
                  "num_witness" : 11
               }
            }
         ]
      ],
      "ref_block_num" : 5294,
      "extensions" : [],
      "signatures" : [
         "1f62a2d3d9cc873f7cf4599a9df27e9521f3257cb723f791aa7e7f8c1e0ab5047d30e84394ecb71f03c593074b91a6ad095d95ce442ef985e0cb11717dd5873a4b"
      ],
      "expiration" : "2015-10-13T19:04:35"
   },
   "jsonrpc" : "2.0",
   "id" : 1
}

@pmconrad
Copy link
Copy Markdown
Contributor

Thanks. Wrt performance, how does it affect replay speed?
Also, to my knowledge leveldb will rebalance its files sometimes, which could lead to unpredictable delays. This would be a no-go for witness nodes (and depending on delay length possibly for public API nodes as well), unless the leveldb-writing is decoupled from main operation.

@bijianing97 bijianing97 changed the base branch from master to develop August 14, 2019 07:20
@pmconrad
Copy link
Copy Markdown
Contributor

Closing in favour of #1954

@pmconrad pmconrad closed this Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants