Event attribute storage method, cumulative calculation method, and device
By storing event attributes on the blockchain, the problem of data tampering is solved, ensuring the credibility and accuracy of risk control decisions and enabling reliable cumulative calculation.
Patent Information
- Application Number
- CN202310438923.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-21
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2043-04-21
AI Technical Summary
In existing technologies, the data storage of event attributes is at risk of being tampered with during the cumulative calculation process, which makes risk control decisions unreliable.
Blockchain technology is used to store event attributes. Event attributes are obtained through blockchain nodes, and statistical calculations are performed based on pre-configured cumulative subjects and objects. Subject values, object values, and indication information are recorded in the block. Once the conditions are met, the data is packaged and stored in the blockchain to ensure that the data cannot be tampered with.
It ensures the immutability of event attribute data, guarantees the credibility and accuracy of risk control decisions, and facilitates the querying of object data for the same subject during cumulative calculation.
Smart Images

Figure CN116467314B_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification belong to the field of blockchain technology, and in particular relate to an event attribute storage method, an accumulation calculation method, and an apparatus. Background Technology
[0002] Currently, cumulative calculations based on event attributes are frequently involved. For example, in risk control scenarios, cumulative calculations are performed on various dimensions such as the amount, environment, and behavior of the entities involved in an event, using different windows and methods, to help identify various risk characteristics. Event: The triggering action for risk control is an event. Events belong to a certain type of control behavior, such as payment events or login events; events contain several attributes. Attributes: Information used to describe when the event occurs.
[0003] In existing technologies, event attribute data is typically stored in data tables. During the cumulative calculation of event attributes, the stored data may be tampered with, making the cumulative calculation results unreliable. Consequently, the entire risk control decision-making process becomes unreliable. Blockchain, on the other hand, is characterized by immutable data. Therefore, a reliable event attribute storage scheme and a cumulative calculation scheme for event attributes need to be designed in conjunction with blockchain. Summary of the Invention
[0004] The purpose of this invention is to provide an event attribute storage method, an event attribute cumulative calculation method and apparatus, which can prevent the stored event attribute data from being tampered with and facilitate the query of object data of the same subject during cumulative calculation.
[0005] The first aspect of this specification provides a method for storing event attributes for cumulative computation, which is executed by a blockchain node in a blockchain system, including:
[0006] Get the values of each attribute corresponding to multiple event attributes of the first event;
[0007] Based on the pre-configured cumulative subject and cumulative object of the cumulative calculation, the attribute value corresponding to the cumulative subject is selected from each attribute value as the first subject value, and the attribute value corresponding to the cumulative object is selected from each attribute value as the first object value; the cumulative calculation is used to perform statistical calculations on each value of the cumulative object for the same cumulative subject in multiple events;
[0008] The first storage unit corresponding to the first event is stored in the first block. The first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value. The first indication information is the hash value of the previous block or the identifier of the current block.
[0009] When preset conditions are met, the first block is packaged and stored in the blockchain.
[0010] In one possible implementation, the first indication information is the hash value of a previous block; after storing the first storage unit corresponding to the first event in the first block, the method further includes:
[0011] The first block stores the second storage unit corresponding to the second event. The second storage unit records the first subject value, the second object value, and the second indication information of the latest block that previously stored the first subject value. The second indication information is the identifier of this block.
[0012] In one possible implementation, the first block further stores a third storage unit corresponding to the third event. The third storage unit records the second subject value, the third object value, and the third indication information of the latest block that previously stored the second subject value. The third indication information is the hash value of the previous block or the identifier of the current block.
[0013] In one possible implementation, the first indication information is the hash value of a previous block; before storing the first storage unit corresponding to the first event in the first block, the method further includes:
[0014] Find the hash value of the latest block corresponding to the first subject value from the pre-stored correspondence table between subject values and latest block identifiers;
[0015] Based on the hash value, locate the second block on the blockchain and verify whether the subject value stored in the second block includes the first subject value.
[0016] Furthermore, after packaging and storing the first block in the blockchain, the method further includes:
[0017] Update the correspondence table so that the hash value of the latest block corresponding to the first subject value is updated to the hash value of the first block.
[0018] In one possible implementation, before storing the first storage unit corresponding to the first event in the first block, the method further includes:
[0019] Based on the attribute values, determine whether the first event satisfies the pre-configured cumulative preconditions;
[0020] When the determination result is that the first event satisfies the cumulative precondition, the first storage unit corresponding to the first event is stored in the first block.
[0021] In one possible implementation, the first event is a risk control event.
[0022] In one possible implementation, the first storage unit also stores a timestamp of the moment the first event occurred.
[0023] In one possible implementation, the packaged first block includes a block header and a block body; the first storage unit is stored in the block body.
[0024] Furthermore, the block header stores the hash value of the previous block and the hash value of the current block.
[0025] In one possible implementation, the method is executed by invoking a pre-deployed smart contract.
[0026] The second aspect of this specification provides a method for the cumulative calculation of event attributes, wherein the event attributes are stored using the method of the first aspect, and the method is executed by a blockchain node in a blockchain system, comprising:
[0027] Determine the target subject value for the current cumulative calculation;
[0028] Obtain the first hash value of the latest block on the blockchain that previously stored the value of the target entity;
[0029] Based on the first hash value, locate the target block on the blockchain, obtain at least one storage unit in the target block that stores the value of the target subject, obtain the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the value of the target subject; based on the second hash value, relocate to the target block on the blockchain until the stopping condition is met, and obtain multiple object values of the accumulated object;
[0030] The cumulative calculation is performed based on the multiple object values obtained from the cumulative object.
[0031] In one possible implementation, the at least one storage unit includes a first storage unit corresponding to a first event and a second storage unit corresponding to a second event, wherein the occurrence time of the first event is earlier than the occurrence time of the second event; the step of obtaining the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the target object value from the at least one storage unit includes:
[0032] Obtain the accumulated object value from the first storage unit and the second hash value of the latest block on the blockchain that previously stored the target object value; obtain the accumulated object value from the second storage unit.
[0033] In one possible implementation, obtaining the first hash value of the latest block on the blockchain that previously stored the value of the target subject includes:
[0034] Obtain the pre-stored table of correspondence between subject values and the latest block identifier;
[0035] Find the first hash value of the latest block corresponding to the target subject value from the correspondence table.
[0036] In one possible implementation, the storage unit also stores a timestamp of the time the event occurred;
[0037] The stopping conditions being met include:
[0038] The second hash value included in the storage unit indicates that it is empty; or...
[0039] The timestamp does not conform to the preset time window.
[0040] In one possible implementation, the cumulative calculation includes any of the following:
[0041] Count, remove duplicates, sum, maximum value, minimum value, average value.
[0042] In one possible implementation, the method is executed by invoking a pre-deployed smart contract.
[0043] A third aspect of this specification provides an event attribute storage device for cumulative calculation, the device being disposed in a blockchain node in a blockchain system, comprising:
[0044] The acquisition unit is used to acquire the attribute values corresponding to the multiple event attributes of the first event;
[0045] The selection unit is used to select the attribute value corresponding to the cumulative subject as the first subject value from the attribute values obtained by the acquisition unit, and select the attribute value corresponding to the cumulative object as the first object value from the attribute values obtained by the acquisition unit, based on the pre-configured cumulative subject and cumulative object of the cumulative calculation; the cumulative calculation is used to perform statistical calculations on the various values of the cumulative object for the same cumulative subject in multiple events;
[0046] A recording unit is used to store a first storage unit corresponding to the first event in a first block. The first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value obtained by the selection unit. The first indication information is the hash value of the previous block or the identifier of the current block.
[0047] The packaging unit is used to package the first block obtained by the recording unit and store it in the blockchain when preset conditions are met.
[0048] This specification provides a fourth aspect of an apparatus for accumulating and calculating event attributes, wherein the event attributes are stored using the apparatus of the third aspect, and the apparatus is disposed on a blockchain node in a blockchain system, comprising:
[0049] The determination unit is used to determine the target subject value of the current cumulative calculation.
[0050] The first acquisition unit is used to acquire the first hash value of the latest block on the blockchain that previously stored the target subject value obtained by the determining unit.
[0051] The second acquisition unit is configured to locate the target block on the blockchain based on the first hash value obtained by the first acquisition unit, acquire at least one storage unit in the target block that stores the value of the target subject, acquire the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the value of the target subject from the at least one storage unit, and relocate to the target block on the blockchain based on the second hash value until the stopping condition is met, thereby obtaining multiple object values of the accumulated object.
[0052] The calculation unit is used to perform cumulative calculations based on the multiple object values of the cumulative object obtained by the second acquisition unit.
[0053] The fifth aspect of this specification provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the methods of the first or second aspect.
[0054] A sixth aspect of this specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of the first aspect or the second aspect.
[0055] The event attribute storage scheme for cumulative computation provided in the embodiments of this specification first obtains the attribute values corresponding to multiple event attributes of a first event; then, according to the pre-configured cumulative subject and cumulative object of cumulative computation, it selects the attribute value corresponding to the cumulative subject as the first subject value and the attribute value corresponding to the cumulative object as the first object value; the cumulative computation is used to perform statistical calculations on the various values of the cumulative object for the same cumulative subject in multiple events; next, it stores the first storage unit corresponding to the first event in the first block, and the first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value; the first indication information is the hash value of the previous block or the identifier of the current block; finally, when the preset conditions are met, the first block is packaged and stored in the blockchain. As can be seen from the above, in the embodiments of this specification, under one event, different cumulative objects of the same cumulative subject are stored in a storage unit under one block. Multiple blocks form a physical linked list. Since the storage unit records the indication information of the latest block that previously stored the value of the same subject, multiple storage units of the same subject form a logical linked list, which facilitates the querying of object data of the same subject during cumulative calculation. In summary, this can prevent the stored event attribute data from being tampered with and facilitate the querying of object data of the same subject during cumulative calculation.
[0056] The cumulative calculation scheme for event attributes provided in the embodiments of this specification involves the following steps: First, a blockchain node in the blockchain system determines the target subject value for the current cumulative calculation. Then, it obtains the first hash value of the latest block on the blockchain that previously stored the target subject value. Next, it locates the target block on the blockchain based on the first hash value, obtains at least one storage unit from the target block that stores the target subject value, obtains the object value of the cumulative object and the second hash value of the latest block on the blockchain that previously stored the target subject value from the at least one storage unit. It then relocates to the target block on the blockchain based on the second hash value until a stopping condition is met, obtaining multiple object values for the cumulative object. Finally, it performs cumulative calculation based on the obtained multiple object values for the cumulative object. As can be seen from the above, in the embodiments of this specification, during cumulative calculation, the first hash value of the latest block on the blockchain that previously stored the target subject's value can be obtained based on the target subject's value. Then, the target block on the blockchain is located based on the first hash value, and at least one storage unit storing the target subject's value is obtained from the target block. Since the storage unit records the indication information of the latest block that previously stored the same subject's value, multiple storage units of the same subject form a logical linked list, facilitating the querying of object data for the same subject during cumulative calculation. In summary, this method can prevent the stored event attribute data from being tampered with and facilitates the querying of object data for the same subject during cumulative calculation. Attached Figure Description
[0057] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0058] Figure 1 A blockchain architecture diagram in one embodiment is shown;
[0059] Figure 2 This is a schematic diagram of the consensus process in the PBFT consensus algorithm;
[0060] Figure 3 A flowchart illustrating an event attribute storage method for cumulative calculation according to one embodiment is shown;
[0061] Figure 4 This diagram illustrates the data structure for storing event attributes of a single event according to one embodiment.
[0062] Figure 5A flowchart illustrating a method for cumulative calculation of event attributes according to one embodiment is shown;
[0063] Figure 6 A schematic diagram illustrating the correspondence between event attributes and attribute values for multiple events according to one embodiment is shown.
[0064] Figure 7 A schematic diagram of the data structure for storing event attributes at time t1 according to one embodiment is shown;
[0065] Figure 8 A schematic diagram of the data structure for storing event attributes at time t2 according to one embodiment is shown;
[0066] Figure 9 A schematic diagram of the data structure for storing event attributes at time t3 according to one embodiment is shown;
[0067] Figure 10 A schematic diagram of the data structure for storing event attributes at time t4 according to one embodiment is shown;
[0068] Figure 11 A schematic block diagram of an event attribute storage device for cumulative calculation is shown according to one embodiment;
[0069] Figure 12 A schematic block diagram of an accumulation calculation device for event attributes according to one embodiment is shown. Detailed Implementation
[0070] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.
[0071] Figure 1 A blockchain architecture diagram from one embodiment is shown. Figure 1 In the blockchain architecture diagram shown, blockchain 100 includes N nodes. Figure 1 The diagram illustrates nodes 1 through 8. The lines connecting the nodes schematically represent P2P (Peer-to-Peer) connections, such as TCP connections, used for data transfer between nodes. These nodes can store the entire ledger, i.e., the state of all blocks and all accounts. Each node in the blockchain can produce the same state by executing the same transactions, and each node can store the same state database.
[0072] In the blockchain field, a transaction refers to a unit of task executed and recorded within the blockchain. A transaction typically includes a From field, a To field, and a Data field. Specifically, in the case of a transfer transaction, the From field represents the account address initiating the transaction (i.e., initiating a transfer task to another account), the To field represents the account address receiving the transaction (i.e., receiving the transfer), and the Data field includes the transfer amount.
[0073] Blockchain provides the functionality of smart contracts. A smart contract on the blockchain is a contract that can be triggered and executed through transactions within the blockchain system. Smart contracts can be defined in the form of code. Calling a smart contract on the blockchain involves initiating a transaction pointing to the smart contract's address, causing each node in the blockchain to run the smart contract code in a distributed manner.
[0074] In a contract deployment scenario, for example, Bob sends a transaction containing information about creating a smart contract (i.e., deploying the contract) to a server such as... Figure 1 In the blockchain shown, the `data` field of the transaction includes the code (such as bytecode or machine code) of the contract to be created, and the `to` field of the transaction is empty, indicating that the transaction is used to deploy the contract. After the nodes reach an agreement through the consensus mechanism, they determine the contract address "0x6f8ae93…". Each node adds a contract account corresponding to the contract address of the smart contract to the state database, allocates state storage corresponding to the contract account, stores the contract code, and saves the hash value of the contract code in the contract's state storage, thus the contract is successfully created.
[0075] In scenarios where contracts are invoked, for example, Bob sends a transaction to a smart contract such as... Figure 1 In the blockchain shown, the `from` field of this transaction is the address of the account of the transaction initiator (i.e., Bob), the `to` field is the aforementioned "0x6f8ae93…", which is the address of the smart contract being invoked, and the `data` field of the transaction includes the method and parameters for invoking the smart contract. After consensus is reached on this transaction in the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract separately, and updating the state database based on the execution of the contract.
[0076] One of the decentralized characteristics that distinguishes blockchain technology from traditional technologies is its distributed ledger system, where records are kept on multiple nodes, rather than a centralized system. For a blockchain system to become a robust, publicly accessible, and tamper-proof decentralized system of honest and trustworthy data records, it needs to ensure the security, clarity, and irreversibility of distributed data records in the shortest possible time. In different types of blockchain networks, consensus algorithms are typically used to maintain consistency across the nodes recording the ledger—the consensus mechanisms mentioned earlier. For example, blockchain nodes can implement block-level consensus mechanisms. After a node (e.g., a unique node) generates a block, if this block is recognized by other nodes, those nodes record the same block. As another example, blockchain nodes can implement transaction-level consensus mechanisms. After a node (e.g., a unique node) acquires a blockchain transaction, if this transaction is recognized by other nodes, each node that recognized the transaction can add it to its own latest maintained block, ultimately ensuring that all nodes produce the same latest block. A consensus mechanism is a mechanism by which blockchain nodes reach a network-wide consensus on block information (or block data), ensuring that the latest block is accurately added to the blockchain. Current mainstream consensus mechanisms include Proof of Work (POW), Proof of Stake (POS), Delegated Proof of Stake (DPoS), and Practical Byzantine Fault Tolerance (PBFT) algorithms. In various consensus algorithms, consensus on a consensus proposal is typically determined after a predetermined number of nodes reach agreement on the proposed data. Specifically, in the PBFT algorithm, for N ≥ 3f+1 consensus nodes, f malicious nodes can be tolerated. That is, when 2f+1 out of N consensus nodes reach agreement, consensus is considered successful.
[0077] Figure 2 This is a schematic diagram of the consensus process in the PBFT consensus algorithm. Figure 2As shown, according to the PBFT consensus algorithm, the consensus process can be divided into four phases: Request, Pre-Prepare (PP), Prepare (P), and Commit (C). Assume a blockchain includes four consensus nodes: n1 to n4. Node n1 is, for example, the master node, and nodes n2 to n4 are, for example, slave nodes. According to the PBFT algorithm, f=1 malicious nodes can be tolerated among nodes n1 to n4. Specifically, in the Request phase, blockchain users can send requests to node n1 through their user devices. These requests can be, for example, in the form of blockchain transactions. In the Pre-Prepare phase, after receiving multiple transactions from one or more user devices, node n1 can package these transactions into a consensus proposal and send the consensus proposal, along with its signature, to other consensus nodes (i.e., nodes n2 to n4) for block generation. The consensus proposal may include information such as the transaction bodies and the submission order of the transactions. In the Prepare phase, each slave node can sign the consensus proposal and send it to the other nodes. Assuming node n4 is a malicious node, after nodes n1, n2, and n3 receive signatures of the consensus proposal from 2f = 2 other consensus nodes, they can determine that the preparation phase is complete and can proceed to the commit phase. For example, if... Figure 2 As shown, after receiving the signatures from nodes n2 and n3, node n1 verifies that both signatures are correct for the consensus proposal, thus determining that the preparation phase is complete. Similarly, after receiving and verifying the signatures from node n3 and node n1 (from the preparation phase), node n2 determines that the preparation phase is complete. In the commit phase, each consensus node signs the consensus proposal and sends it to the other consensus nodes. Each consensus node, after receiving the commit phase signatures from 2f = 2 other consensus nodes, determines that the commit phase is complete and consensus is successful. For example, after receiving and verifying the commit phase signatures from nodes n2 and n3, node n1 determines that the commit phase is complete. Therefore, node n1 can execute the multiple transactions according to the consensus proposal, generate and store a block (e.g., block B1) including the multiple transactions, update the world state based on the execution results of the multiple transactions, and return the execution results of the multiple transactions to the user device. Similarly, after determining that the commit phase is complete, nodes n2 and n3 execute the multiple transactions, update the world state based on the execution results of the multiple transactions, and generate and store a block. Through the above process, storage consistency is achieved among nodes n1, n2, and n3. In other words, even with the presence of a malicious node, nodes n1 through n4 can still achieve successful consensus on the consensus proposal and complete the execution of the block.
[0078] The following is based on Figure 1 The blockchain architecture diagram shown is as follows: Figure 2 The diagram illustrates the consensus process in the PBFT consensus algorithm, and further describes the specific implementation steps of the event attribute storage method and the event attribute cumulative calculation method.
[0079] Figure 3 The diagram illustrates a method for storing event attributes for cumulative computation according to one embodiment. This method is executed by blockchain nodes in a blockchain system, where any node can be any device, platform, or cluster of devices with computing and processing capabilities. Figure 3 As shown, the event attribute storage method for cumulative computation may include the following steps: Step 31, obtaining the attribute values corresponding to multiple event attributes of the first event; Step 32, according to the pre-configured cumulative subject and cumulative object of cumulative computation, selecting the attribute value corresponding to the cumulative subject as the first subject value from the attribute values, and selecting the attribute value corresponding to the cumulative object as the first object value from the attribute values; the cumulative computation is used to perform statistical calculations on the various values of the cumulative object for the same cumulative subject in multiple events; Step 33, storing the first storage unit corresponding to the first event in the first block, the first storage unit recording the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value; the first indication information is the hash value of the previous block or the identifier of the current block; Step 34, when the preset conditions are met, packaging the first block and storing it in the blockchain. The specific execution process of each of the above steps is described below.
[0080] First, in step 31, the attribute values corresponding to the multiple event attributes of the first event are obtained. It can be understood that the multiple event attributes correspond to different dimensions of information about the same event.
[0081] In one example, the first event is a risk control event. This risk control event may include, but is not limited to, payment events, login events, etc. Risk control events are typically triggered by user actions.
[0082] In the embodiments described in this specification, the values of various event attributes corresponding to an event can be obtained at the end of the event or during the event execution. The specific meaning of each event attribute is not limited; for example, it can represent a phone number or address. Table 1 shows the correspondence between event attributes and attribute values for an event.
[0083] Table 1: Correspondence between event attributes and attribute values
[0084]
[0085] The property value corresponding to the event attribute "phone number" in event 1 is A, and the property value corresponding to the event attribute "address" in event 1 is address1.
[0086] In one example, the first event is a risk control event.
[0087] In this example, the risk control event is categorized into a certain type of prevention and control behavior, such as a payment event or a login event. In the risk control decision-making process, some scenarios rely on cumulative calculations for decision-making. For example, in a login prevention scenario, the number of times an account has logged in from different locations within the last N days is accumulated; if this number exceeds a certain threshold, login is blocked. The embodiments in this specification make the stored data less susceptible to tampering, and consequently, the entire decision-making process is more reliable.
[0088] Then, in step 32, based on the pre-configured cumulative subject and cumulative object of the cumulative calculation, the attribute value corresponding to the cumulative subject is selected from each attribute value as the first subject value, and the attribute value corresponding to the cumulative object is selected from each attribute value as the first object value. The cumulative calculation is used to perform statistical calculations on each value of the cumulative object for the same cumulative subject in multiple events. It can be understood that the cumulative subject corresponds to one event attribute among multiple event attributes, and the cumulative object corresponds to another event attribute among multiple event attributes. In the embodiments of this specification, one or more cumulative objects corresponding to one cumulative subject can be configured. When multiple cumulative objects are configured, the cumulative calculation performs statistical calculations on each cumulative object of the same cumulative subject separately.
[0089] Among them, the cumulative subject, also known as the cumulative principal, describes the aggregation dimension, similar to the dimension of group by in structured query language (SQL). It needs to ensure its uniqueness, such as buyer user identifier or seller user identifier.
[0090] Cumulative Object: Also known as cumulative object, it describes query metrics, similar to columns in SQL, such as order number or order amount.
[0091] For example, cumulative calculation has a pre-configured accumulation strategy. The accumulation strategy determines the value retrieval logic of the corresponding accumulation subject and accumulation object when it is configured. For example, the accumulation strategy is configured as: accumulate the login address on the mobile phone number; where the accumulation subject is the mobile phone number, which corresponds to the event attribute mobile, and the accumulation object is the address, which corresponds to the event attribute address. The value retrieval logic of the accumulation subject and accumulation object is to obtain the corresponding attribute value from the event attribute.
[0092] Next, in step 33, the first storage unit corresponding to the first event is stored in the first block. The first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value. The first indication information is the hash value of the previous block or the identifier of the current block. It can be understood that one event corresponds to one storage unit, and one block can store multiple storage units corresponding to multiple events. For example, the first block stores the first storage unit corresponding to the first event, the second storage unit corresponding to the second event, and the third storage unit corresponding to the third event.
[0093] In the embodiments described in this specification, the first block may contain only one storage unit recording the first subject value, or it may contain multiple storage units recording the first subject value. That is, the subject value selected from the attribute values of different events may be different or the same. The first storage unit records the first indication information of the latest block that previously stored the first subject value, so that storage units with the same subject value form a logical linked list, which facilitates the search for storage units with the same subject value during subsequent cumulative calculations.
[0094] When the first block contains only one storage unit recording the first subject value, the aforementioned first indication information is the hash value of the previous block; when the first block contains multiple storage units recording the first subject value, and the first storage unit is the first-ordered unit among the multiple storage units, the aforementioned first indication information is the hash value of the previous block; when the first block contains multiple storage units recording the first subject value, and the first storage unit is not the first-ordered unit among the multiple storage units, the aforementioned first indication information is the identifier of this block. It can be understood that when the first indication information is the hash value of the previous block, it indicates that the latest block that previously stored the first subject value is the previous block; when the first indication information is the identifier of this block, it indicates that the latest block that previously stored the first subject value is this block.
[0095] In one example, the first indication information is the hash value of a previous block; after storing the first storage unit corresponding to the first event in the first block, the method further includes:
[0096] The first block stores the second storage unit corresponding to the second event. The second storage unit records the first subject value, the second object value, and the second indication information of the latest block that previously stored the first subject value. The second indication information is the identifier of this block.
[0097] In this example, the first block contains multiple storage units that record the first subject value, and the first storage unit is the first in the sorted order among the multiple storage units, while the second storage unit is the first in the sorted order among the multiple storage units.
[0098] In one example, the first block also stores a third storage unit corresponding to the third event. The third storage unit records the second subject value, the third object value, and the third indication information of the latest block that previously stored the second subject value. The third indication information is either the hash value of the previous block or the identifier of the current block.
[0099] In this example, the first block contains a first storage unit that records the first subject value, and a third storage unit that records the second subject value. That is, the first block can store multiple storage units corresponding to multiple events, and the subject values recorded in different storage units may be different.
[0100] In one example, the first indication information is the hash value of a previous block; before storing the first storage unit corresponding to the first event in the first block, the method further includes:
[0101] Find the hash value of the latest block corresponding to the first subject value from the pre-stored correspondence table between subject values and latest block identifiers;
[0102] Based on the hash value, locate the second block on the blockchain and verify whether the subject value stored in the second block includes the first subject value.
[0103] In this example, there are no restrictions on the storage method of the above correspondence table. The above correspondence table may not be stored on the blockchain. By performing the aforementioned verification, it can be found that the correspondence table has been tampered with.
[0104] In one example, before storing the first storage unit corresponding to the first event in the first block, the method further includes:
[0105] Based on the attribute values, determine whether the first event satisfies the pre-configured cumulative preconditions;
[0106] When the determination result is that the first event satisfies the cumulative precondition, the first storage unit corresponding to the first event is stored in the first block.
[0107] In this example, the cumulative precondition can be a limitation on the range of attribute values of at least one event attribute. For example, the attribute value of event attribute a can be limited to a first interval range, so that only events that meet the cumulative precondition can be stored.
[0108] In one example, the first storage unit also stores the timestamp of the moment the first event occurred.
[0109] In this example, the timestamp mentioned above can be used to determine whether an event belongs to the corresponding cumulative period during cumulative calculation.
[0110] Cumulative period: Also known as the cumulative period, it describes a time range, similar to filtering by event gmt_occur in the WHERE clause of SQL, such as 7 / 15 / 30 / 60 / 90 days, etc.
[0111] Finally, in step 34, when preset conditions are met, the first block is packaged and stored in the blockchain. It is understood that the embodiments described in this specification can be built based on an existing blockchain architecture, and the consensus mechanism can be an existing proof-of-work mechanism.
[0112] In the embodiments described in this specification, the aforementioned preset conditions may include, but are not limited to, limitations on packaging time or limitations on the size of the packaged contents.
[0113] In the embodiments of this specification, a correspondence table between subject values and the latest block identifier can be maintained. This correspondence table includes the correspondence between the first subject value and the hash value of the latest block. It can be understood that the latest block is the block that records the first subject value.
[0114] In one example, after packaging and storing the first block in the blockchain, the method further includes:
[0115] Update the correspondence table so that the hash value of the latest block corresponding to the first subject value is updated to the hash value of the first block.
[0116] In this example, as the number of stored events increases, the corresponding relationship table is continuously updated, so that the latest block containing the subject value can be queried based on the subject value of the cumulative subject during subsequent cumulative calculation.
[0117] In one example, the packaged first block includes a block header and a block body; the first storage unit is stored in the block body.
[0118] In this example, one storage unit corresponds to one event, and an event can be viewed as a transaction in the blockchain.
[0119] Furthermore, the block header stores the hash value of the previous block and the hash value of the current block.
[0120] In this example, by storing the hash value of the previous block and the hash value of the current block in the block header, a physical linked list is formed between the blocks.
[0121] In one example, the method is executed by invoking a pre-deployed smart contract.
[0122] In this example, the saved code is deployed on the blockchain as a contract. The cumulative saving contract is triggered at the end of each event, ensuring the data saving process is trustworthy. For instance, when a risk control event ends, an instruction is sent to the cumulative saving contract, taking the event attributes, calculated variables, and the expression for the cumulative preconditions as input. The contract calculates the cumulative precondition expression based on the input data, determines whether the conditions are met, and if so, continues executing subsequent code. It also verifies whether the hash value of the previous block with the same subject exists and is correct in the new block content. After successful verification, the accumulated content is saved in the new block. Based on the smart contract, the judgment of the cumulative preconditions is verified by all nodes on the chain.
[0123] Figure 4 This diagram illustrates a data structure for storing event attributes of a single event according to one embodiment. (Refer to...) Figure 4 In this embodiment, two parts of storage are involved. One part of the storage consists of storage units corresponding to events within blocks. These storage units record the subject value, object value, timestamp, and the hash value of the previous block containing the same subject. It can be understood that the timestamp indicates the moment the event occurred, and the hash value corresponds to the aforementioned first indication information. Figure 4 The block only shows one storage unit, which can be considered as a storage unit in the block that does not have other storage units with the same subject value, or the first-ordered storage unit among multiple storage units in the block with the same subject value. Object a and object b are two different cumulative objects, and cumulative calculations can be performed separately for multiple cumulative objects. The hash value of the previous block and the hash value of the current block can be recorded in the block body. Another part of the storage is a storage mapping table, which can maintain the correspondence between subject values and the hash value of the latest block. Among them, the hash value of the latest block in the above mapping is continuously updated as blocks are added, for example, Figure 4 Before a block is packaged and uploaded to the blockchain, the hash value of the latest block corresponding to a main value of 1 in the correspondence table is the hash value of the previous block with the same main body recorded in the main body of that block. Figure 4 After a block is packaged and uploaded to the blockchain, the hash value of the latest block corresponding to the main value 1 in the correspondence table is updated to the hash value of this block recorded in the block header.
[0124] The event attribute storage method for cumulative computation provided in this specification involves a blockchain node in a blockchain system first obtaining the attribute values corresponding to multiple event attributes of a first event; then, based on a pre-configured cumulative subject and cumulative object for cumulative computation, selecting the attribute value corresponding to the cumulative subject as the first subject value and the attribute value corresponding to the cumulative object as the first object value from the attribute values; the cumulative computation is used to perform statistical calculations on the various values of the cumulative object for the same cumulative subject in multiple events; next, a first storage unit corresponding to the first event is stored in a first block, and the first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value; the first indication information is the hash value of the previous block or the identifier of the current block; finally, when preset conditions are met, the first block is packaged and stored in the blockchain. As can be seen from the above, in the embodiments of this specification, under one event, different cumulative objects of the same cumulative subject are stored in a storage unit under one block. Multiple blocks form a physical linked list. Since the storage unit records the indication information of the latest block that previously stored the value of the same subject, multiple storage units of the same subject form a logical linked list, which facilitates the querying of object data of the same subject during cumulative calculation. In summary, this can prevent the stored event attribute data from being tampered with and facilitate the querying of object data of the same subject during cumulative calculation.
[0125] Figure 5 This diagram illustrates a method for cumulative calculation of event attributes according to one embodiment, wherein the event attributes employ... Figure 3 The method shown is used for storage, and this method is executed by blockchain nodes in the blockchain system. Any node in the blockchain system can be any device, platform, or cluster of devices with computing and processing capabilities. For example... Figure 5 As shown, the cumulative calculation method for event attributes may include the following steps: Step 51, determining the target subject value of the current cumulative calculation; Step 52, obtaining the first hash value of the latest block on the blockchain that previously stored the target subject value; Step 53, locating the target block on the blockchain based on the first hash value, obtaining at least one storage unit in the target block that stores the target subject value, obtaining the object value of the cumulative object and the second hash value of the latest block on the blockchain that previously stored the target subject value from the at least one storage unit; relocating to the target block on the blockchain based on the second hash value until a stopping condition is met, obtaining multiple object values of the cumulative object; Step 54, performing cumulative calculation based on the obtained multiple object values of the cumulative object. The specific execution process of each of the above steps is described below.
[0126] First, in step 51, the target value of the cumulative subject for the current cumulative calculation is determined. It is understood that the cumulative subject describes the aggregation dimension, and it typically has multiple possible values. The target value can be any one of these multiple possible values for the cumulative subject. This value can be directly specified by the user, or determined by the user setting query rules based on those rules.
[0127] For example, the cumulative subject is the buyer user identifier, and its possible values include A1, A2, A3, A4, etc. The user can specify the value of the target subject as A2 or A3, etc.
[0128] Then, in step 52, the first hash value of the latest block on the blockchain that previously stored the target subject's value is obtained. It is understood that the blockchain comprises multiple blocks, of which typically only a portion store the target subject's value, while other blocks do not. Therefore, it is necessary to locate the block that stores the target subject's value.
[0129] In one example, obtaining the first hash value of the latest block on the blockchain that previously stored the value of the target subject includes:
[0130] Obtain the pre-stored table of correspondence between subject values and the latest block identifier;
[0131] Find the first hash value of the latest block corresponding to the target subject value from the correspondence table.
[0132] In this example, by looking up the corresponding relationship table, the first hash value can be easily obtained, which can be used to locate the latest block that stores the value of the target subject.
[0133] Next, in step 53, the target block on the blockchain is located based on the first hash value. At least one storage unit storing the target subject value is obtained from the target block. The object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the target subject value are obtained from the at least one storage unit. The target block on the blockchain is then relocated based on the second hash value until a stopping condition is met, resulting in multiple object values of the accumulated object. It is understood that the number of storage units storing the target subject value in the target block can be only one or multiple. At least one storage unit storing the target subject value can be obtained by traversing the target block.
[0134] In one example, the at least one storage unit includes a first storage unit corresponding to a first event and a second storage unit corresponding to a second event, wherein the occurrence time of the first event is earlier than the occurrence time of the second event; the step of obtaining the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the target object value from the at least one storage unit includes:
[0135] Obtain the accumulated object value from the first storage unit and the second hash value of the latest block on the blockchain that previously stored the target object value; obtain the accumulated object value from the second storage unit.
[0136] In this example, if there are multiple storage units in the target block that store the target subject value, the cumulative object value and the second hash value of the latest block on the blockchain that previously stored the target subject value can be obtained from the storage unit that is ranked first. Only the cumulative object value can be obtained from the other storage units.
[0137] In one example, the storage unit also stores a timestamp of the time the event occurred;
[0138] The stopping conditions being met include:
[0139] The second hash value included in the storage unit indicates that it is empty; or...
[0140] The timestamp does not conform to the preset time window.
[0141] In this example, the second hash value being empty indicates that the block containing the storage unit is the first block on the blockchain to store the target subject's value, and there are no blocks storing the target subject's value before this block; the timestamp not conforming to the pre-set time window means that the corresponding event does not belong to the cumulative period corresponding to the cumulative calculation. In both of these cases, the acquisition of the object value of the cumulative object can be stopped.
[0142] Finally, in step 54, cumulative calculations are performed based on the multiple object values of the accumulated object. It can be understood that one object value of the accumulated object can be obtained in one storage unit, and multiple object values of the accumulated object can be obtained in multiple storage units.
[0143] In the embodiments described in this specification, the above-mentioned cumulative calculation is performed using a query function.
[0144] Query functions: Operators that perform statistical calculations on cumulative objects, similar to functions such as COUNT, DISTINCT, and SUM in SQL.
[0145] In one example, the cumulative calculation includes any of the following:
[0146] Count, remove duplicates, sum, maximum value, minimum value, average value.
[0147] In this example, the query operator for counting can be represented as count; the query operator for removing duplicates can be represented as distinct; the query operator for summing can be represented as sum; the query operator for the maximum value can be represented as max; the query operator for the minimum value can be represented as min; and the query operator for the average value can be represented as avg.
[0148] In one example, the method is executed by invoking a pre-deployed smart contract.
[0149] In this example, cumulative computation can also be referred to as a query. The query code is deployed on the blockchain as a contract. Each query triggers the computation of the cumulative query contract, ensuring the reliability of the computation process. For example, in risk control event analysis, if cumulative computation is used, a query command is issued to the cumulative query contract, taking the event attributes and query operators as input parameters. After the cumulative query contract obtains the values of each object of the cumulative object for the same cumulative subject, it performs calculations according to the query operators. Based on the smart contract, the calculation of the query operators is verified by all nodes on the chain.
[0150] The cumulative calculation method for event attributes provided in the embodiments of this specification involves the following steps: First, a blockchain node in the blockchain system determines the target subject value for the current cumulative calculation. Then, it obtains the first hash value of the latest block on the blockchain that previously stored the target subject value. Next, it locates the target block on the blockchain based on the first hash value, obtains at least one storage unit from the target block that stores the target subject value, obtains the object value of the cumulative object and the second hash value of the latest block on the blockchain that previously stored the target subject value from the at least one storage unit. It then relocates to the target block on the blockchain based on the second hash value until a stopping condition is met, obtaining multiple object values for the cumulative object. Finally, it performs cumulative calculation based on the obtained multiple object values for the cumulative object. As can be seen from the above, in the embodiments of this specification, during cumulative calculation, the first hash value of the latest block on the blockchain that previously stored the target subject's value can be obtained based on the target subject's value. Then, the target block on the blockchain is located based on the first hash value, and at least one storage unit storing the target subject's value is obtained from the target block. Since the storage unit records the indication information of the latest block that previously stored the same subject's value, multiple storage units of the same subject form a logical linked list, facilitating the querying of object data for the same subject during cumulative calculation. In summary, this method can prevent the stored event attribute data from being tampered with and facilitates the querying of object data for the same subject during cumulative calculation.
[0151] The following section provides an example illustrating the data structure for storing the event attributes of multiple events occurring sequentially, and presents the results of cumulative calculations based on this data structure. For simplicity, only an example of a block containing one storage unit is used. When a block contains multiple storage units, the data structure is similar, and this embodiment will not elaborate further.
[0152] Figure 6 This diagram illustrates the correspondence between event attributes and attribute values for multiple events according to one embodiment. (Refer to...) Figure 6One cumulative configuration is as follows: accumulate the number of times the phone number and address are recorded, where the number of times each event occurs is fixed at 1; the query function uses `count`. At times t1, t2, t3, and t4, four events occur: event 1, event 2, event 3, and event 4, respectively. For event 1, the attribute value corresponding to the phone number is A, and the attribute value corresponding to the address is address1; for event 2, the attribute value corresponding to the phone number is B, and the attribute value corresponding to the address is address2; for event 3, the attribute value corresponding to the phone number is A, and the attribute value corresponding to the address is address1; for event 4, the attribute value corresponding to the phone number is B, and the attribute value corresponding to the address is address1. In this embodiment, at the end of each event, an accumulation and storage contract can be triggered to store the corresponding storage unit in the block.
[0153] Figure 7 This diagram illustrates the data structure for storing event attributes at time t1 according to one embodiment. (Refer to...) Figure 7 In this embodiment, two parts of storage are involved. One part of the storage consists of a storage unit corresponding to event 1 within a block. The contents recorded in the storage unit include: the accumulated subject is a mobile phone number with the subject value A; the accumulated object includes the number of times with the object value 1; the accumulated object includes an address with the object value address1; the timestamp indicates the time of event occurrence as t1; and the hash value of the previous block with the same subject is null, meaning that the hash value is empty. This can be understood as the mobile phone number A not being recorded in the previous block. The other part of the storage consists of a mapping table, which can maintain the correspondence between the subject value and the hash value of the latest block. Figure 7 After the block with hash value h0 is packaged and added to the blockchain, a new correspondence is added to the mapping table: the latest block corresponding to phone number A has hash value h0. Based on Figure 7 The stored data is used to query the cumulative calculation results corresponding to the cumulative object on the subject value mobile phone number A, and the results are count(times) = 1 and count(address) = 1.
[0154] Figure 8 This diagram illustrates the data structure for storing event attributes at time t2 according to one embodiment. (Refer to...) Figure 8In this embodiment, two parts of storage are involved. One part of the storage consists of a storage unit corresponding to event 2 within a block. The contents recorded in the storage unit include: the accumulated subject is a mobile phone number with the subject value B; the accumulated object includes the number of times with the object value 1; the accumulated object includes an address with the object value address2; a timestamp indicating the time of event occurrence is t2; and the hash value of the previous block with the same subject is null, meaning that the hash value is empty. This can be understood as the mobile phone number B not being recorded in the previous block. The other part of the storage consists of a mapping table, which maintains the correspondence between the subject value and the hash value of the latest block. Figure 8 After the block with hash value h1 is packaged and added to the blockchain, a new correspondence is added to the mapping table: the latest block corresponding to phone number B has hash value h1. Based on Figure 8 The stored data is used to query the cumulative calculation results corresponding to the cumulative object on the subject value mobile phone number B, and the results are count(times) = 1 and count(address) = 1.
[0155] Figure 9 This diagram illustrates the data structure for storing event attributes at time t3 according to one embodiment. (Refer to...) Figure 9 In this embodiment, two parts of storage are involved. One part of the storage consists of a storage unit corresponding to event 3 within a block. The contents recorded in the storage unit include: the accumulated subject is a mobile phone number with the subject value A; the accumulated object includes the number of times recorded with the object value 1; the accumulated object includes an address with the object value address1; a timestamp indicating the time of event occurrence is t3; and the hash value of the previous block with the same subject is h0. That is, the hash value h0 indicates that mobile phone number A has been recorded in a previous block, and the previous block can be located based on this hash value. The other part of the storage consists of a mapping table, which can maintain the correspondence between the subject value and the hash value of the latest block. Figure 9 After the block with hash value h2 is packaged and added to the blockchain, a new correspondence is updated in the mapping table: the hash value of the latest block corresponding to phone number A is updated to h2. Based on Figure 9 The stored data is used to query the cumulative calculation results corresponding to the cumulative object on the subject value mobile phone number A, and the results are count(times) = 2 and count(address) = 1.
[0156] Figure 10 This diagram illustrates the data structure for storing event attributes at time t4 according to one embodiment. (Refer to...) Figure 10In this embodiment, two parts of storage are involved. One part of the storage consists of a storage unit corresponding to event 4 within a block. The contents recorded in the storage unit include: the accumulated subject is a mobile phone number with the subject value B; the accumulated object includes the number of times recorded with the object value 1; the accumulated object includes an address with the object value address1; a timestamp indicating the time of event occurrence is t4; and the hash value of the previous block with the same subject is h1. That is, the hash value h1 indicates that mobile phone number B has been recorded in a previous block, and the previous block can be located based on this hash value. The other part of the storage consists of a mapping table, which can maintain the correspondence between the subject value and the hash value of the latest block. Figure 10 After the block with hash value h3 is packaged and added to the blockchain, a new correspondence is updated in the mapping table: the hash value of the latest block corresponding to phone number B is updated to h3. Based on Figure 10 The stored data shown can be used to query the cumulative calculation results corresponding to the cumulative object on the subject value mobile phone number B, and the results are count(times) = 2 and count(address) = 2.
[0157] According to another embodiment, an event attribute storage device for cumulative computation is provided. This device is disposed on a blockchain node in a blockchain system. The blockchain node in the blockchain system can be any device, platform, or cluster of devices with computing and processing capabilities. This device is used to perform the operations provided in the embodiments of this specification. Figure 3 The method shown. Figure 11 A schematic block diagram of an event attribute storage device for cumulative calculation according to one embodiment is shown. Figure 11 As shown, the device 1100 includes:
[0158] The acquisition unit 111 is used to acquire the attribute values corresponding to the multiple event attributes of the first event;
[0159] The selection unit 112 is used to select the attribute value corresponding to the cumulative subject as the first subject value from the attribute values obtained by the acquisition unit 111, and select the attribute value corresponding to the cumulative object as the first object value from the attribute values obtained by the acquisition unit 111, according to the pre-configured cumulative subject and cumulative object of the cumulative calculation; the cumulative calculation is used to perform statistical calculation on each value of the cumulative object for the same cumulative subject in multiple events.
[0160] The recording unit 113 is used to store the first storage unit corresponding to the first event in the first block. The first storage unit records the first subject value, the first object value and the first indication information of the latest block that previously stored the first subject value obtained by the selection unit 112. The first indication information is the hash value of the previous block or the identifier of the current block.
[0161] Packaging unit 114 is used to package the first block obtained by recording unit 113 and store it in the blockchain when preset conditions are met.
[0162] Optionally, as an embodiment, the first indication information is the hash value of the previous block; the recording unit 113 is further configured to, after storing the first storage unit corresponding to the first event in the first block, store the second storage unit corresponding to the second event in the first block, wherein the second storage unit records the first subject value, the second object value, and the second indication information of the latest block that previously stored the first subject value; the second indication information is the identifier of this block.
[0163] Optionally, as an embodiment, the first block further stores a third storage unit corresponding to the third event. The third storage unit records the second subject value, the third object value, and the third indication information of the latest block that previously stored the second subject value. The third indication information is the hash value of the previous block or the identifier of the current block.
[0164] Optionally, as an embodiment, the first indication information is the hash value of a previous block; the apparatus further includes:
[0165] The lookup unit is used to look up the hash value of the latest block corresponding to the first subject value from a pre-stored correspondence table between the subject value and the latest block identifier before the recording unit 113 stores the first storage unit corresponding to the first event in the first block.
[0166] The verification unit is used to locate the second block on the blockchain based on the hash value obtained by the search unit, and to verify whether the subject value stored in the second block includes the first subject value.
[0167] Furthermore, the device also includes:
[0168] The update unit is used to update the correspondence table after the packaging unit 114 packages the first block and stores it in the blockchain, so that the hash value of the latest block corresponding to the first subject value is updated to the hash value of the first block.
[0169] Optionally, as an embodiment, the apparatus further includes:
[0170] The judgment unit is used to determine whether the first event meets the pre-configured cumulative preconditions based on the attribute values before the recording unit 113 stores the first storage unit corresponding to the first event in the first block.
[0171] The triggering unit is used to execute the first storage unit corresponding to the first event in the first block when the judgment result of the judgment unit is that the first event satisfies the cumulative precondition.
[0172] Optionally, as an example, the first event is a risk control event.
[0173] Optionally, as an embodiment, the first storage unit also stores a timestamp of the time when the first event occurred.
[0174] Optionally, as an embodiment, the packaged first block includes a block header and a block body; the first storage unit is stored in the block body.
[0175] Furthermore, the block header stores the hash value of the previous block and the hash value of the current block.
[0176] Alternatively, as an example, the device executes by invoking a pre-deployed smart contract.
[0177] Through the event attribute storage device for cumulative calculation provided in the embodiments of this specification, the blockchain node in the blockchain system first obtains the attribute values corresponding to multiple event attributes of the first event through the acquisition unit 111; then, the selection unit 112 selects the attribute value corresponding to the cumulative subject as the first subject value and the attribute value corresponding to the cumulative object as the first object value from the attribute values according to the pre-configured cumulative subject and cumulative object of the cumulative calculation; the cumulative calculation is used to perform statistical calculations on each value of the cumulative object for the same cumulative subject in multiple events; next, the recording unit 113 stores the first storage unit corresponding to the first event in the first block, and the first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value; the first indication information is the hash value of the previous block or the identifier of the current block; finally, the packaging unit 114 packages the first block and stores it in the blockchain when the preset conditions are met. As can be seen from the above, in the embodiments of this specification, under one event, different cumulative objects of the same cumulative subject are stored in a storage unit under one block. Multiple blocks form a physical linked list. Since the storage unit records the indication information of the latest block that previously stored the value of the same subject, multiple storage units of the same subject form a logical linked list, which facilitates the querying of object data of the same subject during cumulative calculation. In summary, this can prevent the stored event attribute data from being tampered with and facilitate the querying of object data of the same subject during cumulative calculation.
[0178] According to another embodiment, an accumulation calculation device for event attributes is provided, wherein the event attributes employ... Figure 11 The aforementioned device performs storage and is located on a blockchain node in a blockchain system. A blockchain node in a blockchain system can be any device, platform, or cluster of devices with computing and processing capabilities. This device is used to execute the functions provided in the embodiments of this specification. Figure 5 The method shown. Figure 12 A schematic block diagram of an accumulation calculation device for event attributes according to one embodiment is shown. Figure 12 As shown, the device 1200 includes:
[0179] Determining unit 121 is used to determine the target subject value of the current cumulative calculation.
[0180] The first acquisition unit 122 is used to acquire the first hash value of the latest block on the blockchain that previously stored the target subject value obtained by the determination unit 121;
[0181] The second acquisition unit 123 is configured to locate the target block on the blockchain according to the first hash value obtained by the first acquisition unit 122, acquire at least one storage unit in the target block that stores the value of the target subject, acquire the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the value of the target subject from the at least one storage unit; relocate to the target block on the blockchain according to the second hash value, until the stopping condition is met, and obtain multiple object values of the accumulated object;
[0182] The calculation unit 124 is used to perform cumulative calculation based on the multiple object values of the cumulative object obtained by the second acquisition unit 123.
[0183] Optionally, as an embodiment, the at least one storage unit includes a first storage unit corresponding to a first event and a second storage unit corresponding to a second event, wherein the occurrence time of the first event is earlier than the occurrence time of the second event; the second acquisition unit 123 is specifically used to acquire the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the target object value from the first storage unit; and to acquire the object value of the accumulated object from the second storage unit.
[0184] Optionally, as an embodiment, the first acquisition unit 122 includes:
[0185] The sub-unit is used to retrieve the pre-stored correspondence table between the main values and the latest block identifier;
[0186] The lookup sub-unit is used to find the first hash value of the latest block corresponding to the target subject value from the correspondence table obtained by the acquisition sub-unit.
[0187] Optionally, as an embodiment, the storage unit also stores a timestamp of the time the event occurred;
[0188] The stopping conditions being met include:
[0189] The second hash value included in the storage unit indicates that it is empty; or...
[0190] The timestamp does not conform to the preset time window.
[0191] Optionally, as an embodiment, the cumulative calculation includes any of the following:
[0192] Count, remove duplicates, sum, maximum value, minimum value, average value.
[0193] Alternatively, as an example, the device executes by invoking a pre-deployed smart contract.
[0194] Using the event attribute-based cumulative calculation device provided in the embodiments of this specification, the blockchain node in the blockchain system first determines the target subject value of the current cumulative calculation subject through the determining unit 121; then, the first obtaining unit 122 obtains the first hash value of the latest block on the blockchain that previously stored the target subject value; next, the second obtaining unit 123 locates the target block on the blockchain according to the first hash value, obtains at least one storage unit in the target block that stores the target subject value, obtains the object value of the cumulative object and the second hash value of the latest block on the blockchain that previously stored the target subject value from the at least one storage unit; relocates to the target block on the blockchain according to the second hash value, until the stopping condition is met, and obtains multiple object values of the cumulative object; finally, the calculation unit 124 performs cumulative calculation based on the obtained multiple object values of the cumulative object. As can be seen from the above, in the embodiments of this specification, during cumulative calculation, the first hash value of the latest block on the blockchain that previously stored the target subject's value can be obtained based on the target subject's value. Then, the target block on the blockchain is located based on the first hash value, and at least one storage unit storing the target subject's value is obtained from the target block. Since the storage unit records the indication information of the latest block that previously stored the same subject's value, multiple storage units of the same subject form a logical linked list, facilitating the querying of object data for the same subject during cumulative calculation. In summary, this method can prevent the stored event attribute data from being tampered with and facilitates the querying of object data for the same subject during cumulative calculation.
[0195] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0196] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0197] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0198] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes the elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.
[0199] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0200] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0201] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0202] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0203] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0204] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0205] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0206] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0207] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0208] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0209] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of these embodiments. Various modifications and variations can be made to these embodiments by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.
Claims
1. A method for storing event attributes for cumulative computation, the method being executed by a blockchain node in a blockchain system, comprising: Get the values of each attribute corresponding to multiple event attributes of the first event; Based on the pre-configured cumulative subject and cumulative object, select the attribute value corresponding to the cumulative subject from each attribute value as the first subject value, and select the attribute value corresponding to the cumulative object from each attribute value as the first object value. The cumulative calculation is used to perform statistical calculations on each value of the cumulative object for the same cumulative subject in multiple events; The first storage unit corresponding to the first event is stored in the first block. The first storage unit records the first subject value, the first object value, and the first indication information of the latest block that previously stored the first subject value. The first indication information is either the hash value of a previous block or the identifier of the current block; When preset conditions are met, the first block is packaged and stored in the blockchain.
2. The method according to claim 1, wherein, The first indication information is the hash value of the previous block; After storing the first storage unit corresponding to the first event in the first block, the method further includes: The first block stores the second storage unit corresponding to the second event. The second storage unit records the first subject value, the second object value, and the second indication information of the latest block that previously stored the first subject value. The second indication information is the identifier of this block.
3. The method according to claim 1, wherein, The first block also stores a third storage unit corresponding to the third event. The third storage unit records the value of the second subject, the value of the third object, and the third indication information of the latest block that previously stored the value of the second subject. The third indication information is either the hash value of the previous block or the identifier of the current block.
4. The method according to claim 1, wherein, The first indication information is the hash value of the previous block; before storing the first storage unit corresponding to the first event in the first block, the method further includes: Find the hash value of the latest block corresponding to the first subject value from the pre-stored correspondence table between subject values and latest block identifiers; Based on the hash value, locate the second block on the blockchain and verify whether the subject value stored in the second block includes the first subject value.
5. The method according to claim 4, wherein, After packaging and storing the first block in the blockchain, the method further includes: Update the correspondence table so that the hash value of the latest block corresponding to the first subject value is updated to the hash value of the first block.
6. The method according to claim 1, wherein, Before storing the first storage unit corresponding to the first event in the first block, the method further includes: Based on the attribute values, determine whether the first event satisfies the pre-configured cumulative preconditions; When the determination result is that the first event satisfies the cumulative precondition, the first storage unit corresponding to the first event is stored in the first block.
7. The method according to claim 1, wherein, The first event is a risk control event.
8. The method according to claim 1, wherein, The first storage unit also stores the timestamp of the moment the first event occurred.
9. The method according to claim 1, wherein, The packaged first block includes a block header and a block body; the first storage unit is stored in the block body.
10. The method according to claim 9, wherein, The block header stores the hash value of the previous block and the hash value of the current block.
11. The method according to claim 1, wherein, The method is executed by invoking a pre-deployed smart contract.
12. A method for cumulative calculation of event attributes, wherein the event attributes are stored using the method described in claim 1, and the method is executed by a blockchain node in a blockchain system, comprising: Determine the target subject value for the current cumulative calculation; Obtain the first hash value of the latest block on the blockchain that previously stored the value of the target entity; Based on the first hash value, locate the target block on the blockchain, obtain at least one storage unit in the target block that stores the value of the target subject, obtain the cumulative object value and the second hash value of the latest block on the blockchain that previously stored the value of the target subject from the at least one storage unit; Based on the second hash value, the target block on the blockchain is relocated until the stopping condition is met, and multiple object values of the accumulated object are obtained. The cumulative calculation is performed based on the multiple object values obtained from the cumulative object.
13. The method according to claim 12, wherein, The at least one storage unit includes a first storage unit corresponding to a first event and a second storage unit corresponding to a second event, wherein the occurrence time of the first event is earlier than the occurrence time of the second event; The step of obtaining the object value of the accumulated object from the at least one storage unit and the second hash value of the latest block on the blockchain that previously stored the target object value includes: Obtain the accumulated object value from the first storage unit and the second hash value of the latest block on the blockchain that previously stored the target object value; Obtain the object value of the accumulated object from the second storage unit.
14. The method according to claim 12, wherein, The step of obtaining the first hash value of the latest block on the blockchain that previously stored the value of the target entity includes: Obtain the pre-stored table of correspondence between subject values and the latest block identifier; Find the first hash value of the latest block corresponding to the target subject value from the correspondence table.
15. The method according to claim 12, wherein, The storage unit also stores a timestamp of the time the event occurred; The stopping conditions being met include: The second hash value included in the storage unit indicates that it is empty; or, The timestamp does not conform to the preset time window.
16. The method according to claim 12, wherein, The cumulative calculation includes any of the following: Count, remove duplicates, sum, maximum value, minimum value, average value.
17. The method according to claim 12, wherein, The method is executed by invoking a pre-deployed smart contract.
18. An event attribute storage device for cumulative calculation, the device being disposed on a blockchain node in a blockchain system, comprising: The acquisition unit is used to acquire the attribute values corresponding to the multiple event attributes of the first event; The selection unit is used to select the attribute value corresponding to the cumulative subject as the first subject value from the attribute values obtained by the acquisition unit, based on the pre-configured cumulative subject and cumulative object of the cumulative calculation, and to select the attribute value corresponding to the cumulative object as the first object value from the attribute values. The cumulative calculation is used to perform statistical calculations on each value of the cumulative object for the same cumulative subject in multiple events; A recording unit is used to store a first storage unit corresponding to the first event in a first block. The first storage unit records the first subject value, the first object value, and the first indication information of the latest block where the first subject value was previously stored, obtained by the selection unit. The first indication information is either the hash value of a previous block or the identifier of the current block; The packaging unit is used to package the first block obtained by the recording unit and store it in the blockchain when preset conditions are met.
19. An apparatus for accumulating event attributes, wherein the event attributes are stored using the apparatus of claim 18, the apparatus being disposed on a blockchain node in a blockchain system, comprising: The determining unit is used to determine the target value of the cumulative subject for the current cumulative calculation; The first acquisition unit is used to acquire the first hash value of the latest block on the blockchain that previously stored the target subject value obtained by the determining unit. The second acquisition unit is used to locate the target block on the blockchain according to the first hash value obtained by the first acquisition unit, acquire at least one storage unit in the target block that stores the value of the target subject, acquire the object value of the accumulated object and the second hash value of the latest block on the blockchain that previously stored the value of the target subject from the at least one storage unit; Based on the second hash value, the target block on the blockchain is relocated until the stopping condition is met, and multiple object values of the accumulated object are obtained. The calculation unit is used to perform cumulative calculations based on the multiple object values of the cumulative object obtained by the second acquisition unit.
20. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-17.
21. A computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 1-17.
Citation Information
Patent Citations
Log recording and querying method and device, computer equipment and storage medium
CN115687505A