diff --git a/src/gausskernel/security/gs_ledger/blockchain.cpp b/src/gausskernel/security/gs_ledger/blockchain.cpp index 23c0d946f..98310ffa7 100644 --- a/src/gausskernel/security/gs_ledger/blockchain.cpp +++ b/src/gausskernel/security/gs_ledger/blockchain.cpp @@ -30,6 +30,32 @@ #include "libpq/md5.h" #include "gs_ledger/blockchain.h" #include "utils/snapmgr.h" +/*Blockchain was first used in the Bitcoin project to provide a distributed accounting +platform for the operation of Bitcoin. With the development of blockchain technology, +the definition of blockchain is that a blockchain is a distributed database, which maintains +a continuously growing data record chain and can prevent data from being tampered with. +It consists of data structure blocks, which hold proprietary data in the initial blockchain +implementation, and the data and programs are saved in some recent implementations, +and each block holds some personal transaction data and block execution results. Each +block contains a timestamp and information of the previous block. Blockchain is a +decentralized recording technology. In other words, any node participating in the system +may not belong to the same organization and need not trust each other; Blockchain +data is maintained by all node functions, and each participating node can copy and +obtain a complete copy of the record. + +The basic concepts of blockchain are: +Transaction: that is, an operation that changes the account book status once, such as adding a record. + +Block: It records the transactions and status results in a period of time, +which is a consensus on the current account book status. + +Chain: It is composed of blocks connected in series according to +the sequence of occurrence, and it is a log record of the whole state change. + +If the blockchain is regarded as a state machine, each transaction is an attempt to change the state, +and the block generated by each consensus is the result that +the parameter confirms the state change caused by all the transactions in the block. +*/ /* * gen_global_hash -- generate globalhash of gchain @@ -41,6 +67,11 @@ * * Note: globalhash is generated by operate info and previous globalhash using md5. */ + +/*Function name: gen_ Global_ Hash +Formal parameters: (hash32_t * hash_buffer, const char * info_string, bool exist, const hash32_t * prev_hash) +Return value: bool +Generate global hash for gchain*/ bool gen_global_hash(hash32_t *hash_buffer, const char *info_string, bool exist, const hash32_t *prev_hash) { errno_t rc = EOK; @@ -87,6 +118,11 @@ bool gen_global_hash(hash32_t *hash_buffer, const char *info_string, bool exist, * cmd_text: the command query which modified user table. * rel_hash: rel_hash of current block. */ +/*Function name: set_ Gchain_ Comb_ String +Formal parameters (const char * dbname, const char * username, +Const char * nsp_ Name, const char * rel_ Name, const char * cmd_ Text, uint64 rel_ Hash) +Return value: char* +Set combo block information*/ char *set_gchain_comb_string(const char *db_name, const char *user_name, const char *nsp_name, const char *rel_name, const char *cmd_text, uint64 rel_hash) { @@ -113,6 +149,10 @@ char *set_gchain_comb_string(const char *db_name, const char *user_name, * into gchain cache for next block. Thus, previous global hash is * come from cache directly. */ +/*Function name: ledger_ Gchain_ Append +Formal parameters: (Oid relid, const char * query_string, uint64 cn_hash) +Return value: void +Record the block to gchain.*/ void ledger_gchain_append(Oid relid, const char *query_string, uint64 cn_hash) { Datum current_time; @@ -173,6 +213,10 @@ void ledger_gchain_append(Oid relid, const char *query_string, uint64 cn_hash) * operation: command operation. * hash: the hash that prepare to append. */ +/*Function name: ledger_ Output_ Append_ Hash +Formal parameters: (char * resp_tag, CmdType operation, uint64 hash) +Return value: void +Append relhash to the response tag.*/ static void ledger_output_append_hash(char *resp_tag, CmdType operation, uint64 hash) { Assert(resp_tag != NULL); @@ -202,6 +246,10 @@ static void ledger_output_append_hash(char *resp_tag, CmdType operation, uint64 * use es_modifiedRowHash to receive all DN relhash and accumulate them * as cn_relhash for insertion. */ +/*Function name: ledger_ ExecutorEnd +Formal parameter: (QueryDesc * query_desc) +Return value: void +Record the end block to gchain.*/ static void ledger_ExecutorEnd(QueryDesc *query_desc) { uint64 hashsum; @@ -302,6 +350,10 @@ void opfusion_ledger_ExecutorEnd(FusionType fusiontype, Oid relid, const char *q /* * ledger_hook_init -- install of gchain block record hook. */ +/*Function name: ledger_ Hook_ Init +Formal parameter: void +Return value: void +The gchain block records the installation of hooks.*/ void ledger_hook_init(void) { t_thrd.security_ledger_cxt.prev_ExecutorEnd = (void *)ExecutorEnd_hook; @@ -311,6 +363,10 @@ void ledger_hook_init(void) /* * ledger_hook_fini -- uninstall of gchain block record hook. */ +/*Function name: ledger_ Hook_ Init +Formal parameter: void +Return value: void +The gchain block records the installation of hooks.*/ void ledger_hook_fini(void) { ExecutorEnd_hook = (ExecutorEnd_hook_type)t_thrd.security_ledger_cxt.prev_ExecutorEnd;