Micro power transaction method based on blockchain smart contract
By leveraging the collaboration of dual smart contracts and dynamic threshold matching in blockchain smart contracts, the problem of low automation in the distribution microgrid power trading system has been solved, enabling accurate generation and automated matching of trading intentions, thereby improving trading efficiency and data reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG UNIV OF TECH
- Filing Date
- 2026-04-28
- Publication Date
- 2026-06-26
AI Technical Summary
Existing microgrid power trading systems suffer from low automation, weak robustness in transaction matching, poor settlement efficiency, and insufficient data reliability, failing to meet the needs of large-scale distributed energy trading.
By employing a blockchain-based smart contract approach, through dual smart contract collaboration, dynamic threshold matching, and end-to-end on-chain notarization, we can achieve accurate generation, automated matching, and deviation settlement of transaction intentions, thereby ensuring the integrity and credibility of transaction data.
It significantly improves the automation level and system robustness of micro-electricity trading, increases trading efficiency and data processing efficiency, reduces the cost of manual participation, and optimizes the overall operation.
Smart Images

Figure CN122115110B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electricity trading technology, and particularly relates to a method for micro-electricity trading based on blockchain smart contracts. Background Technology
[0002] Currently, in distribution microgrid power trading scenarios, centralized platform architectures are commonly used. A central node handles data statistics, transaction matching, fund settlement, and information storage. This relies on manual intervention and fixed rules to generate, match, and settle transaction intentions, resulting in a low degree of standardization and automation. Furthermore, the industry has not yet deeply integrated time-series forecasting, blockchain storage, and smart contract execution. Microgrid power generation, load, and electricity price data lack accurate time-series extrapolation capabilities, and the transparency, tamper-proof capabilities, and full-process traceability of transaction information are insufficient to meet the demands of large-scale distributed energy trading.
[0003] Existing electricity trading matching mechanisms mostly use fixed threshold matching, without considering real-time load fluctuations in the blockchain network. In high-concurrency scenarios, problems such as matching congestion and decreased accuracy are prone to occur. The transaction execution and deviation settlement links lack dual-contract collaborative management, and the deviation between actual electricity consumption data and contractually agreed electricity cannot be automatically calculated. The reliability of settlement data stored on the blockchain is insufficient. As a result, the overall trading system has technical defects such as low automation, weak matching robustness, poor settlement efficiency, and insufficient data credibility, which restrict the marketization, intelligentization, and large-scale development of power trading in distribution networks and microgrids. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a method for micro-electricity trading based on blockchain smart contracts. Through dual smart contract collaboration, dynamic threshold matching, and full-process on-chain notarization, it can achieve automated, efficient, reliable, and traceable micro-electricity trading, significantly improving transaction efficiency and system robustness.
[0005] To achieve the above objectives, the technical solution provided by this invention is a method for micro-electricity trading based on blockchain smart contracts, comprising the following steps:
[0006] Step 1: Perform time-series extrapolation analysis on the historical operating data of microgrid nodes and the electricity price configuration data of distribution network nodes to obtain the predicted operating data of microgrid nodes and the predicted electricity price time-series values of distribution network nodes;
[0007] Step 2: Compare the power purchase and sale surplus of the predicted operating data and the predicted electricity price time series value, and decompose the obtained surplus results based on the preset electricity price gradient to obtain the transaction intention items of the microgrid nodes.
[0008] Step 3: Digest the transaction intention entries, and store the resulting hash digests and transaction intention entries on the blockchain to obtain the on-chain transaction intention records of the microgrid nodes;
[0009] Step 4: Based on the first smart contract on the blockchain network, traverse and match the on-chain transaction intention records, and dynamically and adaptively adjust the matching threshold of the first smart contract based on the load status of the blockchain network to obtain the matching pairs of the first smart contract.
[0010] Step 5: Based on the first smart contract, perform contract orchestration on the matching entries to obtain the smart contract instance to be executed for the first smart contract;
[0011] Step 6: Based on the second smart contract on the blockchain network, perform deviation settlement between the actual execution data of the microgrid node and the smart contract instance to be executed to obtain the settlement data of the second smart contract;
[0012] Step 7: Write the settlement data into the blockchain network to obtain the stored settlement record of the second smart contract.
[0013] Preferably, in step 1, obtaining the predicted operating data of the microgrid nodes and the predicted electricity price time series values of the distribution network nodes includes:
[0014] Periodic features are extracted from the historical power generation sequence of microgrid nodes to obtain the power generation trend feature value of microgrid nodes, and fluctuation feature decomposition is performed on the historical load power sequence of microgrid nodes to obtain the load fluctuation feature components of microgrid nodes.
[0015] Based on the characteristic values of power generation trends and the characteristic components of load fluctuations, time-series trend fitting is performed on the power generation and load power of microgrid nodes during the forecast period to obtain the predicted operating data of microgrid nodes.
[0016] The electricity price fluctuation cycle is identified by analyzing the historical time-of-use electricity price series to obtain the electricity price fluctuation cycle parameters of the distribution network nodes;
[0017] Based on the electricity price fluctuation cycle parameter, the electricity price changes within the prediction period are time-series mapped to obtain the predicted electricity price time-series values for distribution network nodes.
[0018] Preferably, in step 2, the transaction intention entries of the microgrid nodes are obtained, including:
[0019] The predicted power generation and predicted load power values in the predicted operation data are used to determine the power surplus, and the power surplus status value of the microgrid node is obtained.
[0020] The surplus status value of electricity and the predicted electricity price point value in the predicted electricity price time series value are combined and matched to obtain the surplus result entries of the microgrid nodes.
[0021] The preset electricity price gradient is decomposed to obtain the electricity price range of the preset electricity price gradient, and the predicted electricity price point value in the surplus result item is assigned to the electricity price range to obtain the intention label of the electricity price range.
[0022] By associating and integrating the power surplus status value and the intention tag, the transaction intention entries of the microgrid node are obtained.
[0023] Preferably, in step 3, the on-chain transaction intention records of the microgrid nodes are obtained, including:
[0024] Key domains are extracted from the transaction intention entries to obtain the transaction intention data to be summarized for each transaction intention entry;
[0025] Based on the hash generation interface on the blockchain network, the transaction intention data to be digested is cryptographically hashed to obtain the hash digest returned by the hash generation interface;
[0026] Based on the blockchain network transaction data encapsulation format, the hash digest is associated with the transaction intention entry to obtain the transaction data package to be uploaded to the blockchain of the microgrid node, and the transaction data package is submitted to the evidence storage smart contract on the blockchain network to obtain the evidence storage transaction hash returned by the evidence storage smart contract.
[0027] Based on the hash of the evidence storage transaction, the evidence storage result of the evidence storage smart contract is parsed to obtain the on-chain transaction intention record of the microgrid node.
[0028] Preferably, in step 4, the matching pairs obtained from the first smart contract include:
[0029] Based on the first smart contract on the blockchain network, the on-chain transaction intention records are filtered and collected to obtain the microgrid node's transaction intention dataset to be matched.
[0030] The purchase intention and sale intention of electricity in the dataset of transaction intentions to be matched are matched and identified. Based on the timestamp field of the on-chain transaction intention record, the matching identification results are merged by time to obtain the initial matching candidate set of the first smart contract.
[0031] The dynamic load coefficient of the first smart contract is obtained by dynamically calculating the current number of pending transactions and the current block generation interval of the blockchain network:
[0032] ;
[0033] Where L represents the current dynamic load factor, N represents the current number of transactions pending processing, N0 represents the baseline number of transactions pending processing, T represents the current block generation interval, and T0 represents the baseline block generation interval. This represents the difference between the current number of pending transactions and the number of pending transactions at the previous time. Indicates the instantaneous load weighting coefficient. This represents the processing efficiency weighting coefficient. Indicates the load change weighting coefficient;
[0034] Based on the current dynamic load coefficient and the preset baseline threshold, the matching threshold of the first smart contract is located by key value to obtain the update matching threshold of the first smart contract.
[0035] Based on the updated matching threshold and the initial matching candidate set, the initial matching candidate set is prioritized. When the matching priority meets the updated matching threshold, the matching pair of the first smart contract is obtained.
[0036] Preferably, the initial matching candidate set is prioritized. When the matching priority meets the update matching threshold, the matching pair entry of the first smart contract is obtained. The specific process is as follows:
[0037] The smaller value between the electricity demand value of the intended electricity purchase and the electricity supply value is used as the electricity matching base value of the first smart contract;
[0038] Based on the electricity matching baseline, a Gaussian kernel mapping is applied to the absolute value of the difference between the intended electricity price for purchasing and the intended electricity price for selling, to obtain the matching priority factor of the initial matching candidate set. The Gaussian kernel mapping calculation formula is as follows:
[0039] ;
[0040] S is the matching priority factor; the larger the value, the higher the priority. This is the absolute difference between the intended purchase price and the intended sale price of electricity. As the base value for battery power matching, Gaussian kernel bandwidth;
[0041] Based on the matching priority factor, the matching candidate pairs in the initial matching candidate set are sorted in descending order to obtain the priority ranking sequence of electricity purchase intentions;
[0042] Based on the priority sorting sequence and the updated matching threshold, the priority sorting sequence is selected in ascending order to obtain the matching pair entries of the first smart contract.
[0043] Preferably, in step 5, the smart contract instance to be executed for the first smart contract is obtained, including:
[0044] Based on the matching entries, attribute access is performed on the matching entries to obtain the orchestration parameter set of the first smart contract;
[0045] The power purchase microgrid node identifiers and power sales microgrid node identifiers in the parameter set are used to map the contract participant addresses, and on-chain identity queries are performed on the blockchain network to obtain the participant address pairs of the first smart contract.
[0046] Based on the participant address pairs and the orchestration parameter set, placeholders are filled into the contract terms of the preset smart contract template, and the filled contract terms are encapsulated and deployed to obtain the initial contract instance of the first smart contract.
[0047] The initial contract instance is logically self-consistent, and its state field is updated to the pending execution state to obtain the pending execution smart contract instance of the first smart contract.
[0048] Preferably, the initial contract instance is logically self-consistent, and its state field is updated to a pending execution state to obtain the first smart contract instance to be executed. The specific process is as follows:
[0049] The initial contract instance is parsed using contract syntax, and the parsing result of the initial contract instance is verified using an instruction set whitelist based on the contract virtual machine of the blockchain network to obtain the syntax pass mark of the first smart contract.
[0050] Based on the syntax and the identifier, the mutual exclusion of the agreed electricity value of the initial contract instance with the electricity demand value and the electricity supply value in the orchestration parameter set is determined, and the electricity constraint verification result of the first smart contract is obtained.
[0051] Based on the power constraint verification results, the payment terms and agreed power values in the initial contract instance are verified by value stream verification to obtain the logical self-consistency verification identifier of the first smart contract.
[0052] Based on the logical self-consistency verification identifier, the state field of the initial contract instance is changed from the initial state to the pending execution state, thus obtaining the pending execution smart contract instance of the first smart contract.
[0053] Preferably, in step 6, the settlement data of the second smart contract is obtained, including:
[0054] The actual power generation value and actual load power value in the actual execution data of microgrid nodes are separated from the agreed power value by removing the difference, and the result of the actual execution data is obtained.
[0055] The deviation power value and deviation direction identifier of the stripping result are aggregated to obtain the deviation identification result of the second smart contract;
[0056] Based on the deviation identification results and the deviation settlement logic built into the second smart contract, the settlement path is confirmed for the deviation direction identifier and the deviation power value to obtain the deviation settlement amount of the second smart contract.
[0057] Based on the deviation settlement amount and the participant account addresses of the smart contract instance to be executed, fund transfer instructions are assembled for the payer account and payee account identified by the deviation direction to obtain the settlement data of the second smart contract.
[0058] Preferably, in step 7, the stored settlement record of the second smart contract is obtained, including:
[0059] The settlement data is serialized and assembled into a transaction payload, and the notarization transaction body is generated for the notarization interface of the second smart contract to obtain the notarization transaction to be submitted for the second smart contract.
[0060] The transaction to be submitted for evidence storage is signed with a private key, and the signed transaction is broadcast to the transaction pool to obtain the broadcast transaction identifier of the blockchain network;
[0061] The status of the block production of broadcast transaction identifiers is polled and monitored to obtain on-chain transaction receipts from the blockchain network;
[0062] Based on the on-chain transaction receipts, ABI decoding is performed on the contract event logs of the on-chain transaction receipts to extract the stored settlement records of the second smart contract.
[0063] The present invention has the following beneficial effects:
[0064] This invention achieves accurate generation of transaction intentions through time-series extrapolation parsing and electricity price gradient decomposition, and employs hash encryption and on-chain notarization mechanisms to ensure the integrity and reliability of transaction data. It enables fully automated management and control of the entire micro-electricity transaction process, significantly improving the stability of transaction execution and data processing efficiency. Relying on the collaborative operation of dual smart contracts, it can quickly complete transaction intention matching, contract orchestration, and deviation settlement, reducing manual intervention costs and shortening the overall transaction cycle.
[0065] This invention dynamically and adaptively adjusts the matching threshold based on the blockchain network load status, which can improve the accuracy of transaction matching and the system's adaptability, ensuring smooth transaction matching in high-concurrency scenarios. The deviation settlement process automatically calculates the actual data against the contractual agreement and transfers funds, with settlement data uploaded to the blockchain in real time for notarization, improving the response speed and reliability of the settlement process and comprehensively optimizing the overall operation of micro-electricity trading. Attached Figure Description
[0066] Figure 1 This is a schematic flowchart of the method of the present invention;
[0067] Figure 2 A simulation diagram of the dynamic load and matching performance of the smart contract for power trading in a microgrid. Detailed Implementation
[0068] The embodiments of the present invention will be further described below with reference to the accompanying drawings:
[0069] like Figure 1 As shown, the method for micro-electricity trading based on blockchain smart contracts includes the following steps:
[0070] Step 1: Perform time-series extrapolation analysis on the historical operating data of microgrid nodes and the electricity price configuration data of distribution network nodes to obtain the predicted operating data of microgrid nodes and the predicted electricity price time-series values of distribution network nodes;
[0071] Step 2: Compare the power purchase and sale surplus of the predicted operating data and the predicted electricity price time series value, and decompose the obtained surplus results based on the preset electricity price gradient to obtain the transaction intention items of the microgrid nodes.
[0072] Step 3: Digest the transaction intention entries, and store the resulting hash digests and transaction intention entries on the blockchain to obtain the on-chain transaction intention records of the microgrid nodes;
[0073] Step 4: Based on the first smart contract on the blockchain network, traverse and match the on-chain transaction intention records, and dynamically and adaptively adjust the matching threshold of the first smart contract based on the load status of the blockchain network to obtain the matching pairs of the first smart contract.
[0074] Step 5: Based on the first smart contract, perform contract orchestration on the matching entries to obtain the smart contract instance to be executed for the first smart contract;
[0075] Step 6: Based on the second smart contract on the blockchain network, perform deviation settlement between the actual execution data of the microgrid node and the smart contract instance to be executed to obtain the settlement data of the second smart contract;
[0076] Step 7: Write the settlement data into the blockchain network to obtain the stored settlement record of the second smart contract.
[0077] In step 1, the predicted operating data of microgrid nodes and the predicted electricity price time series values of distribution network nodes are obtained, including:
[0078] Periodic features are extracted from the historical power generation sequence of microgrid nodes to obtain the power generation trend feature value of microgrid nodes, and fluctuation feature decomposition is performed on the historical load power sequence of microgrid nodes to obtain the load fluctuation feature components of microgrid nodes.
[0079] Based on the characteristic values of power generation trends and the characteristic components of load fluctuations, time-series trend fitting is performed on the power generation and load power of microgrid nodes during the forecast period to obtain the predicted operating data of microgrid nodes.
[0080] The electricity price fluctuation cycle is identified by analyzing the historical time-of-use electricity price series to obtain the electricity price fluctuation cycle parameters of the distribution network nodes;
[0081] Based on the electricity price fluctuation cycle parameter, the electricity price changes within the prediction period are time-series mapped to obtain the predicted electricity price time-series values for distribution network nodes.
[0082] Historical power generation data of microgrid nodes over the past 12 months were selected to form a historical power generation sequence. The data was divided into segments with each day as a 24-hour period. The power generation variation patterns within each time segment were compared, and the starting value, ending value, direction of change, and duration of power generation within each time segment were extracted. These extracted information were then integrated into the power generation trend characteristic value of the microgrid node. Simultaneously, historical load power data of microgrid nodes over the past 12 months were selected to form a historical load power sequence. The historical load power sequence was divided into load power subsequences for fixed time periods each day, with each week as a decomposition period. The load power variation amplitude within each subsequence was then analyzed, and subsequences with consistent variation amplitudes were grouped into the same category. The load power variation characteristics corresponding to each category of subsequences are the load fluctuation characteristic components of the microgrid node.
[0083] Based on the time span of the prediction period, which is preset to the next 7 days, with each day being 24 hours, and combined with the obtained power generation trend characteristic values, and referring to the power generation trend of the corresponding period in the historical power generation power sequence, the power generation trend characteristic values are mapped to each time unit of the prediction period. This determines the direction and approximate range of power generation change in each time unit within the prediction period. Then, combined with the load fluctuation characteristic components, the load change pattern consistent with the load fluctuation characteristic components in the historical load power sequence is matched, and this pattern is mapped to each time unit of the prediction period to determine the load power change in each time unit within the prediction period. By integrating the power generation and load power data of all time units within the prediction period, the predicted operation data of the microgrid nodes is obtained.
[0084] Historical time-of-use (TOU) electricity price data for the past 6 months is collected to form a historical TOU electricity price sequence. The electricity price data is divided into 24 time periods per day, and the average electricity price for each time period on different dates is calculated. The average electricity price for the same time period on each day is compared with the average electricity price for the same time period on adjacent dates. If the change in the average electricity price for the same time period on three consecutive days does not exceed 0.05 yuan / kWh, then the time span of these three dates is determined as a basic cycle. This process is repeated to verify the electricity price change pattern on subsequent days. If the electricity price change pattern of the subsequent three consecutive basic cycles is completely consistent, then this basic cycle is determined as the electricity price fluctuation cycle parameter of the distribution network node.
[0085] Using the established electricity price fluctuation cycle parameters as a reference, the electricity price values and change patterns for each time period within the cycle are extracted. The prediction period is then segmented according to the electricity price fluctuation cycle parameters, ensuring that the number of segments matches the duration of the electricity price fluctuation cycle parameters. The electricity price values and change patterns for each time period within the electricity price fluctuation cycle parameters are then mapped one by one to the corresponding segments of the prediction period. Based on the actual duration of the prediction period, the electricity price data for the last incomplete cycle is supplemented, ultimately yielding the electricity price values for each time unit of the distribution network node within the prediction period. These values are then integrated to form the predicted electricity price time series values for the distribution network node.
[0086] By extracting generation trend features from the historical power generation sequence of microgrid nodes over the past 12 months and decomposing the historical load power sequence to obtain load fluctuation feature components, and combining these two to fit the power generation and load power for the prediction period, accurate predictive operation data can be obtained, avoiding prediction bias. Furthermore, by identifying the electricity price fluctuation cycle parameter from the historical time-of-use price sequence of distribution network nodes over the past 6 months and mapping it to the price changes for the prediction period, accurate time-series values of predicted electricity prices can be obtained. The entire process is specific and reproducible, clearly defining data selection criteria, division basis, and judgment conditions, eliminating the need for fuzzy operations. This effectively solves the problems of inaccurate and unreliable acquisition of microgrid predictive operation data and distribution network predicted electricity price time-series values, providing accurate data support for the coordinated operation of microgrids and distribution networks, and ensuring the orderly implementation of subsequent related control work.
[0087] The time-series forecasting method in this embodiment exhibits good robustness and versatility. Addressing the issue that actual electricity prices are susceptible to complex factors such as weather, holidays, and grid faults, it employs an adaptive sliding window and dynamic threshold to identify electricity price fluctuation cycles. The threshold can be adaptively adjusted in real time according to meteorological conditions, holiday types, load characteristics, and fault states, no longer limited to fixed values and fixed cycles. Simultaneously, the forecasting process incorporates multi-dimensional features such as historical power, historical electricity prices, meteorological information, holiday markers, load types, fault identifiers, and grid constraints as inputs. Abnormal data removal eliminates the impact of data spikes caused by sudden disturbances, and it supports flexible access and replacement of various general-purpose time-series forecasting models. This allows it to adapt to dynamic operating environment changes in different scenarios, effectively improving the accuracy and applicability of the forecast results.
[0088] In step 2, the transaction intention entries of the microgrid nodes are obtained, including:
[0089] The predicted power generation and predicted load power values in the predicted operation data are used to determine the power surplus, and the power surplus status value of the microgrid node is obtained.
[0090] The surplus status value of electricity and the predicted electricity price point value in the predicted electricity price time series value are combined and matched to obtain the surplus result entries of the microgrid nodes.
[0091] The preset electricity price gradient is decomposed to obtain the electricity price range of the preset electricity price gradient, and the predicted electricity price point value in the surplus result item is assigned to the electricity price range to obtain the intention label of the electricity price range.
[0092] By associating and integrating the power surplus status value and the intention tag, the transaction intention entries of the microgrid node are obtained.
[0093] The predicted power generation and predicted load power values for each time unit in the predicted operation data of the microgrid nodes are extracted. Each pair of values for each time unit is compared. When the predicted power generation is greater than the predicted load power, the difference is calculated and used as the power surplus for that time unit, and the power surplus status is recorded as positive surplus. When the predicted power generation equals the predicted load power, the power surplus is recorded as 0, and the power surplus status is recorded as no surplus. When the predicted power generation is less than the predicted load power, the difference is calculated and its absolute value is taken as the power deficit for that time unit, and the power surplus status is recorded as negative surplus. The power surplus status information from all time units is integrated to obtain the power surplus status value of the microgrid node.
[0094] The obtained electricity surplus status values are split into time units, so that each time unit corresponds to an independent electricity surplus status information. At the same time, the predicted electricity price point value corresponding to each time unit is extracted from the predicted electricity price time series value. The electricity surplus status values and predicted electricity price point values of the same time unit are matched one-to-one, and each combination corresponds to an independent record. Each record clearly marks the electricity surplus status, the specific surplus or deficit amount, and the corresponding predicted electricity price point value of the time unit. After integrating all such records, the surplus result entries of the microgrid nodes are obtained.
[0095] The preset electricity price gradient is divided into four fixed intervals: 0-0.3 yuan / kWh, 0.3-0.6 yuan / kWh, 0.6-0.9 yuan / kWh, and above 0.9 yuan / kWh. This preset electricity price gradient is then broken down and deconstructed to clarify the starting and ending prices for each interval, determining the specific range of each interval and forming the electricity price intervals of the preset electricity price gradient. Each predicted electricity price point in the surplus result entries is judged one by one and compared with the range of each electricity price interval to determine the unique electricity price interval to which the predicted electricity price point belongs. Then, a fixed intention label is assigned to each electricity price interval: 0-0.3 yuan / kWh corresponds to "low electricity price purchase intention," 0.3-0.6 yuan / kWh corresponds to "regular electricity purchase intention," 0.6-0.9 yuan / kWh corresponds to "regular electricity sales intention," and above 0.9 yuan / kWh corresponds to "high electricity price sales intention," thus obtaining the intention label for the electricity price interval to which each predicted electricity price point belongs.
[0096] The power surplus status value corresponding to each time unit is associated with the intention tag corresponding to the predicted electricity price point value of that time unit. The power surplus status, specific surplus or deficit amount, and corresponding intention tag of each time unit are clearly marked to ensure that the two pieces of information in the same time unit correspond one-to-one without omission. Then, the associated information of all time units is integrated in chronological order to form a complete record entry. Each record entry clearly contains three core pieces of information: time unit, power surplus status value, and intention tag. After integration, the transaction intention entries of the microgrid nodes are obtained.
[0097] By comparing the predicted power generation and load values in the forecast operation data on a time-by-time basis, the criteria and specific types for determining the surplus status value are clarified, ensuring accurate and reproducible surplus status determination. The surplus status value is combined and matched with the predicted electricity price point value to form surplus result entries. Combined with the electricity price range after decomposition by the preset electricity price gradient, the attribution mapping of the predicted electricity price point value and the assignment of intention labels are realized, ensuring accurate label correspondence. By linking and integrating the surplus status value and intention labels, the transaction intention entries of microgrid nodes can be clearly obtained. The entire process is clear in steps and specific in judgment criteria, effectively solving the problems of inaccurate acquisition of transaction intention entries and unclear logic. This provides a clear and reliable basis for the power purchase and sale transaction decisions of microgrid nodes, improving the rationality and operability of transaction decisions.
[0098] In step 3, the on-chain transaction intention records of the microgrid nodes are obtained, including:
[0099] Key domains are extracted from the transaction intention entries to obtain the transaction intention data to be summarized for each transaction intention entry;
[0100] Based on the hash generation interface on the blockchain network, the transaction intention data to be digested is cryptographically hashed to obtain the hash digest returned by the hash generation interface;
[0101] Based on the blockchain network transaction data encapsulation format, the hash digest is associated with the transaction intention entry to obtain the transaction data package to be uploaded to the blockchain of the microgrid node, and the transaction data package is submitted to the evidence storage smart contract on the blockchain network to obtain the evidence storage transaction hash returned by the evidence storage smart contract.
[0102] Based on the hash of the evidence storage transaction, the evidence storage result of the evidence storage smart contract is parsed to obtain the on-chain transaction intention record of the microgrid node.
[0103] Pre-defined rules for extracting key domains from transaction intention entries are established. The key domains to be extracted include three core elements: time unit, power surplus status value, and intention tag. Key domains are identified and extracted from each transaction intention entry according to these rules. Only the specific numerical information corresponding to each key domain is retained, and redundant fields without actual data significance are removed. All extracted key domain information is integrated to form the transaction intention data to be summarized for each transaction intention entry.
[0104] Obtain a pre-deployed hash generation interface in the blockchain network, input the transaction intention data to be digested into the hash generation interface, and the hash generation interface performs a complete hash operation on the transaction intention data to be digested according to the preset cryptographic hash processing logic. During the operation, each bit of the data is encoded and transformed one by one to ensure that every character of the data participates in the operation. Finally, the hash generation interface outputs a fixed-length string result, which is the hash digest.
[0105] The system acquires a predefined transaction data encapsulation format from the blockchain network. This format explicitly requires that the hash digest and the transaction intention entry be associated and bound in the form of key-value pairs. According to this encapsulation format, the hash digest is used as the key and the transaction intention entry is used as the corresponding value field to complete the association and binding operation between the two, forming a transaction data package to be uploaded to the blockchain for the microgrid node. Subsequently, the transaction data package to be uploaded to the blockchain is submitted to a pre-deployed evidence storage smart contract on the blockchain network. After receiving the data package, the evidence storage smart contract executes the preset evidence storage verification logic to verify the format compliance and data integrity of the data package. After the verification is successful, a unique evidence storage transaction hash is generated and returned. This evidence storage transaction hash is a unique identifier string assigned by the evidence storage smart contract.
[0106] The system retrieves the pre-defined parsing rules for the evidence storage results from the smart contract. These rules specify that three core pieces of information—the transaction hash, the timestamp, and the on-chain status identifier—must be extracted from the returned results. Following these rules, the system parses each field of the evidence storage results returned by the smart contract, extracting the specific string corresponding to the transaction hash, the specific time information corresponding to the timestamp, and the specific status value corresponding to the on-chain status identifier. All the parsed information is then integrated according to a pre-defined record structure to form a complete record containing the transaction hash, timestamp, on-chain status identifier, and the core information of the original transaction intention entry. This record is the on-chain transaction intention record of the microgrid node.
[0107] By extracting key fields such as time unit, power surplus status value, and intention tag from transaction intention entries, the transaction intention data to be summarized is obtained. Redundant information is removed to ensure that the summary data is accurate and concise. Cryptographic hashing of the data to be summarized is performed on the data based on the blockchain hash generation interface to ensure that the data is tamper-proof and to obtain a unique hash digest. The hash digest and transaction intention entry are bound according to the blockchain transaction encapsulation format, submitted to the notarization smart contract, and the notarized transaction hash is obtained through compliance verification. The notarization result is then parsed to obtain the on-chain transaction intention record. The entire process is clear and reproducible, solving the problems of non-standard notarization of transaction intention entries, easy data tampering, and poor traceability of notarization results. It realizes secure on-chain notarization of transaction intention entries, ensures the authenticity and integrity of transaction intention data, provides reliable on-chain evidence for the traceability and verification of electricity purchase and sale transactions in microgrid nodes, and improves the standardization and security of the transaction process.
[0108] In step 4, the matching entries for the first smart contract are obtained, including:
[0109] Based on the first smart contract on the blockchain network, the on-chain transaction intention records are filtered and collected to obtain the microgrid node's transaction intention dataset to be matched.
[0110] The purchase intention and sale intention of electricity in the dataset of transaction intentions to be matched are matched and identified. Based on the timestamp field of the on-chain transaction intention record, the matching identification results are merged by time to obtain the initial matching candidate set of the first smart contract.
[0111] The dynamic load coefficient of the first smart contract is obtained by dynamically calculating the current number of pending transactions and the current block generation interval of the blockchain network:
[0112] ;
[0113] Where L represents the current dynamic load factor, N represents the current number of transactions pending processing, N0 represents the baseline number of transactions pending processing, T represents the current block generation interval, and T0 represents the baseline block generation interval. This represents the difference between the current number of pending transactions and the number of pending transactions at the previous time. Indicates the instantaneous load weighting coefficient. This represents the processing efficiency weighting coefficient. Indicates the load change weighting coefficient;
[0114] Based on the current dynamic load coefficient and the preset baseline threshold, the matching threshold of the first smart contract is located by key value to obtain the update matching threshold of the first smart contract.
[0115] Based on the updated matching threshold and the initial matching candidate set, the initial matching candidate set is prioritized. When the matching priority meets the updated matching threshold, the specific process is as follows:
[0116] The smaller value between the electricity demand value of the intended electricity purchase and the electricity supply value is used as the electricity matching base value of the first smart contract;
[0117] Based on the electricity matching baseline, a Gaussian kernel mapping is applied to the absolute value of the difference between the intended electricity price for purchasing and the intended electricity price for selling, to obtain the matching priority factor of the initial matching candidate set. The Gaussian kernel mapping calculation formula is as follows:
[0118] ;
[0119] S is the matching priority factor; the larger the value, the higher the priority. This is the absolute difference between the intended purchase price and the intended sale price of electricity. The base value for matching electricity volume is the smaller of the electricity demand and the electricity supply. Gaussian kernel bandwidth;
[0120] Based on the matching priority factor, the matching candidate pairs in the initial matching candidate set are sorted in descending order to obtain the priority ranking sequence of electricity purchase intentions;
[0121] Based on the priority sorting sequence and the updated matching threshold, the priority sorting sequence is selected in ascending order to obtain the matching pair entries of the first smart contract.
[0122] The first smart contract pre-deployed on the blockchain network is retrieved. This contract has built-in filtering rules for on-chain transaction intention records. The rules clearly state that five core fields need to be extracted from the on-chain transaction intention records: time unit, power surplus status value, intention tag, notarized transaction hash, and notarized timestamp. According to the filtering rules, all transaction intention records that have been uploaded to the blockchain network are extracted and filtered one by one. Records with missing fields or formats that do not meet the preset requirements are eliminated. All the remaining transaction intention records after filtering are collected in the order of timestamps and integrated to form the microgrid node's unmatched transaction intention dataset.
[0123] The system iterates through each transaction intention record in the dataset of transaction intentions to be matched, identifies the transaction type corresponding to the intention tag in each record, and groups records with intention tags of low-price electricity purchase intention and regular electricity purchase intention into a purchase intention set, and records with intention tags of regular electricity sales intention and high-price electricity sales intention into a sales intention set. Then, it matches and identifies the records in the purchase intention set and the sales intention set one by one. The matching benchmark is that the surplus or deficit of electricity in the purchase intention and the surplus or deficit of electricity in the sales intention are consistent in the same time unit. The record pairs that meet the matching benchmark are selected as the preliminary matching results. Then, the timestamp field of the on-chain transaction intention records corresponding to all preliminary matching results is extracted, and all preliminary matching results corresponding to the same timestamp are merged by time. The merged matching results are arranged in the order of timestamp to form the initial matching candidate set of the first smart contract.
[0124] The system obtains real-time feedback from the blockchain network's node monitoring module regarding the current number of pending transactions, the current block generation interval, and the difference between the current number of pending transactions and the previous number of pending transactions. Based on pre-defined load factor calculation rules, it calculates the relative ratio of the number of pending transactions to the benchmark. Block interval relative to the benchmark multiple Transaction increment fluctuation item The three ratios are weighted. =0.3、 =0.4、 A linear weighted sum is applied to the base value of 0.3, and the resulting sum is the current dynamic load coefficient of the first smart contract, because the number of transactions to be processed is relative to the base multiple. The normal range for the project is [0, 2], and the block interval is a multiple of the benchmark. The normal range is [0, 2], and the transaction increment fluctuation term is... The normal range is [-0.5, 0.5], and the weights are... , , The sum of is 1, and the overall output after weighting is strictly constrained to [0, 2]. In addition, the power trading of microgrids is a low-frequency to medium-frequency trading scenario, and the blockchain load will not experience extreme overload. After 6 months of actual testing, the extreme value of network load does not exceed twice the benchmark. Therefore, the value range of this coefficient is 0 to 2. The larger the coefficient value, the higher the current load level of the blockchain network.
[0125] Meanwhile, to prevent the dynamic load coefficient from becoming negative, a lower limit constraint is set for the final calculation result: when the weighted summation result is less than 0, the dynamic load coefficient is forcibly assigned a value of 0, thereby ensuring that its value range is always [0, 2].
[0126] The key-value mapping table of matching thresholds and dynamic load coefficients pre-established in the first smart contract is retrieved. This mapping table presets matching thresholds corresponding to different load coefficient ranges. Specifically, the matching threshold is 80 for dynamic load coefficients in the range of 0 to 0.5, 60 for the range of 0.5 to 1, 40 for the range of 1 to 1.5, and 20 for the range of 1.5 to 2. Based on the calculated current dynamic load coefficient, the coefficient range to which it belongs is determined, and the matching threshold corresponding to that range is located in the key-value mapping table. This matching threshold is then used as the update matching threshold for the first smart contract.
[0127] Extract the matching priority identifier of each pair of matching results in the initial matching candidate set. This identifier is determined by two indicators: the matching degree of the timestamps of the electricity purchase intention and the electricity sales intention, and the matching degree of the electricity surplus in the pairing results. The matching degree of both indicators is set to 100 points as the maximum score. The specific score of the matching priority identifier is obtained by arithmetically averaging the matching degrees of the two indicators. The matching priority identifier score of each pair of matching results is compared with the updated matching threshold one by one. When the matching priority identifier score is greater than or equal to the updated matching threshold, the pairing result is determined as the matching pair entry of the first smart contract. Integrate all matching results that meet the conditions to form a complete set of matching pair entries.
[0128] Each parameter in the dynamic load factor formula has a clear and unique source, with no redundancy and no repetition of the preceding process. The current number of pending transactions N is obtained by the blockchain network's node monitoring module, which collects real-time data on all transactions not yet included in blocks and counts them one by one. The current block generation interval T is also recorded in real-time by the same node monitoring module, specifically the complete time interval from the initiation of the block generation instruction to the completion of the block packaging confirmation. The baseline number of pending transactions N0 is determined by collecting historical operational data from the blockchain network over the past six months, extracting the number of pending transactions for each fixed time period daily, calculating the average for each time period, and then performing an overall arithmetic average of all time periods. This serves as a benchmark for assessing whether the current number of pending transactions is normal. The baseline block generation interval T0 is a preset standard duration, set at 10 minutes, based on the regular frequency of microgrid electricity purchase and sale transactions during the blockchain network deployment phase and after multiple rounds of real-time testing and verification. This meets the real-time requirements for microgrid transaction intention matching.
[0129] Difference To obtain the number of pending transactions, N must first be extracted from the node monitoring module at the current moment, then the number of pending transactions recorded by the module at the previous moment must be extracted. The result is then calculated by subtracting the number of pending transactions from the previous moment from the current N. This is used to reflect the instantaneous changes in the number of transactions to be processed. Instantaneous load weighting coefficient. Processing efficiency weighting coefficient Load change weighting coefficient These are all fixed values preset after testing and optimization, based on the load fluctuation patterns of the blockchain network over the past 6 months and the actual needs of microgrid power purchase and sale transactions. They are set to 0.3, 0.4, and 0.3 respectively to ensure that the influence weight of each load-related indicator on the dynamic load coefficient is reasonable.
[0130] The core significance of this dynamic load coefficient formula is to integrate and calculate various dispersed parameters reflecting the blockchain network load, transforming scattered load-related information into a single quantitative indicator, thereby achieving a precise and intuitive assessment of the real-time load level of the blockchain network. The calculation results directly serve the dynamic adaptive adjustment of the first smart contract matching threshold, providing a clear and quantifiable core basis for threshold adjustment and avoiding the imbalance between matching efficiency and accuracy caused by a fixed threshold: when the blockchain network load is higher, the matching threshold is increased accordingly, allowing only high-priority transactions to enter the matching process, thereby reducing the inflow of concurrent transactions and effectively alleviating network congestion; when the network load is lower, the matching threshold is decreased, appropriately relaxing transaction access conditions to improve transaction matching coverage, ultimately ensuring that the acquisition of entries for the first smart contract matching pair is both efficient and accurate, aligning with the core requirements of real-time performance and reliability for microgrid power purchase and sale transactions.
[0131] The parameters in the dynamic load factor formula are clearly sourced and traceable. They are determined through real-time data collection by the blockchain node monitoring module, historical data statistics, and preset optimization, ensuring their authenticity and reliability. This provides a precise foundation for formula calculation and avoids load assessment bias caused by ambiguous parameters. By integrating various load-related parameters, the formula quantifies dispersed blockchain load information into a single dynamic load factor, enabling accurate assessment of the real-time load of the blockchain network. This provides a quantifiable basis for the dynamic adaptive adjustment of the first smart contract matching threshold. Adjusting the matching threshold based on this coefficient can improve the efficiency of transaction intention matching under high blockchain load and ensure matching accuracy under low load. This effectively solves the efficiency and accuracy imbalance caused by fixed matching thresholds, ensuring efficient and accurate acquisition of matching entries for the first smart contract. This further guarantees the real-time performance and reliability of microgrid power purchase and sale transactions, providing stable support for the transaction matching process.
[0132] Extract the specific electricity volume information for each pair of electricity purchase intentions and electricity sales intentions from the initial matching candidate set. Clarify that the electricity demand value corresponding to the electricity purchase intention is its electricity shortage, and the electricity supply value corresponding to the electricity sales intention is its electricity surplus. Compare the electricity demand value and the electricity supply value in the same pairing candidate one by one, and select the electricity value with the smaller value as the electricity matching base value of the first smart contract. This ensures that the electricity matching base value always matches the actual tradable electricity volume of the paired parties, providing an accurate electricity benchmark for subsequent priority determination.
[0133] Based on a defined electricity matching baseline, the intended electricity price for purchasing and selling in the pairing candidate is extracted. The difference between the two prices is calculated and its absolute value is taken. The absolute value of the price difference is then processed by Gaussian kernel mapping. During the mapping process, the electricity matching baseline is used as a reference to associate the absolute value of the price difference with the electricity matching baseline. This ensures that the mapping result reflects the combined effect of electricity matching degree and price difference. The value obtained after mapping is the matching priority factor of the initial matching candidate set. The larger the factor value, the higher the matching priority of the pairing candidate.
[0134] Collect the matching priority factors corresponding to all paired candidates in the initial matching candidate set, and sort them in descending order according to the value of the matching priority factors. During the sorting process, compare the factor values of each paired candidate one by one, and put the paired candidates with larger factor values first and the paired candidates with smaller factor values last. If there are two paired candidates with completely identical matching priority factor values, then sort them according to the order of their corresponding timestamps, with the paired candidate with the earlier timestamp first. The complete sequence formed after sorting is the priority sorting sequence of purchase intentions.
[0135] Extract the determined update matching threshold of the first smart contract and clarify that this threshold is the judgment standard for priority screening. Then, select the priority ranking sequence of electricity purchase intentions in ascending order. Assuming that the current priority ranking sequence is A(95), B(90), C(85), D(80), E(75) arranged from high to low according to the matching priority factor, set the update matching threshold to select the top 3 best matching pairs. At this time, starting from the first position of the sequence (highest priority), select matching candidates that meet the quantity requirements in turn. A, B, and C can be selected as the matching pair entries of the first smart contract. In the selection process, starting from the first position of the priority ranking sequence, select the matching candidates in the sequence in turn until the number of selected matching candidates reaches the number corresponding to the update matching threshold. Stop the selection and integrate all the selected matching candidates to form a complete matching result set. This set is the matching pair entry of the first smart contract, ensuring that the selected matching candidates are all valid pairs with high priority and meet the threshold requirements.
[0136] By selecting the smaller value between the electricity demand and the electricity supply as the electricity matching baseline, the system ensures that the matching baseline aligns with the actual tradable electricity volume of both parties, providing precise support for priority determination and avoiding unreasonable matching due to baseline deviation. Based on this baseline, a Gaussian kernel mapping is applied to the absolute value of the price difference between the intended electricity purchase and sale prices to obtain a matching priority factor that comprehensively reflects both the electricity matching degree and the price difference, achieving precise quantification of pairing priority. By arranging the matching priority factors in descending order to form a priority ranking sequence, the priority of pairing candidates is clearly defined. Then, combined with an ascending selection based on the updated matching threshold, pairing candidates meeting the priority requirements are screened, resulting in the first smart contract's matching pair entry. The entire process is clearly defined, with specific judgment criteria and strong reproducibility, effectively solving the problems of ambiguous pairing priority determination and inaccurate matching results. This ensures that the matching pair entries align with the microgrid electricity purchase and sale transaction needs, improving the rationality and accuracy of transaction matching and providing reliable support for the orderly development of microgrid electricity purchase and sale transactions.
[0137] In step 5, the instance of the first smart contract to be executed is obtained, including:
[0138] Based on the matching entries, attribute access is performed on the matching entries to obtain the orchestration parameter set of the first smart contract;
[0139] The power purchase microgrid node identifiers and power sales microgrid node identifiers in the parameter set are used to map the contract participant addresses, and on-chain identity queries are performed on the blockchain network to obtain the participant address pairs of the first smart contract.
[0140] Based on the participant address pairs and the orchestration parameter set, placeholders are filled into the contract terms of the preset smart contract template, and the filled contract terms are encapsulated and deployed to obtain the initial contract instance of the first smart contract.
[0141] The initial contract instance is logically self-consistent, and its state field is updated to a pending execution state to obtain the first smart contract instance to be executed. The specific process is as follows:
[0142] The initial contract instance is parsed using contract syntax, and the parsing result of the initial contract instance is verified using an instruction set whitelist based on the contract virtual machine of the blockchain network to obtain the syntax pass mark of the first smart contract.
[0143] Based on the syntax and the identifier, the mutual exclusion of the agreed electricity value of the initial contract instance with the electricity demand value and the electricity supply value in the orchestration parameter set is determined, and the electricity constraint verification result of the first smart contract is obtained.
[0144] Based on the power constraint verification results, the payment terms and agreed power values in the initial contract instance are verified by value stream verification to obtain the logical self-consistency verification identifier of the first smart contract.
[0145] Based on the logical self-consistency verification identifier, the state field of the initial contract instance is changed from the initial state to the pending execution state, thus obtaining the pending execution smart contract instance of the first smart contract.
[0146] The system extracts six core attribute information from the matching entries: microgrid node identifier for power purchase, microgrid node identifier for power sale, matched electricity value, matched electricity price time sequence value, notarized transaction hash, and notarized timestamp. Following the parameter extraction rules built into the first smart contract, the system accesses and retrieves the above attributes for each matching entry one by one, retaining only information with complete attribute values and formats that meet the preset requirements. All accessed attribute information is integrated and categorized according to the preset field order to form the orchestration parameter set of the first smart contract. This parameter set provides complete basic data support for subsequent contract orchestration.
[0147] The system retrieves the pre-configured mapping table between microgrid node identifiers and blockchain network addresses from the first smart contract. This mapping table is established through the initial node registration process, clearly defining the unique blockchain network address corresponding to each microgrid node identifier. According to this mapping table, the addresses of the electricity purchasing microgrid node identifiers and electricity selling microgrid node identifiers in the orchestration parameter set are mapped respectively to obtain the corresponding blockchain network addresses. Subsequently, an on-chain identity query request is initiated to the blockchain network. During the query process, it verifies whether the mapped address is a registered and normal participant address. After successful verification, the address corresponding to the electricity purchasing microgrid node and the address corresponding to the electricity selling microgrid node are combined to form the participant address pair of the first smart contract, ensuring that the participant address is real, valid, and can be used for subsequent contract interactions.
[0148] The first smart contract template, pre-stored in the first smart contract, is retrieved. This template contains five core contract terms: contract subject information, transaction terms, execution logic, default handling, and termination conditions. Each term has a corresponding type of placeholder. The participant address field in the contract subject information is filled according to the participant address matching the electricity purchase microgrid node address and the electricity sales microgrid node address. The transaction terms field is filled according to the matching electricity value and matching electricity price time sequence value in the orchestration parameter set. The data traceability field in the execution logic is filled according to the notarized transaction hash. The corresponding terms are filled according to the preset default handling standards and termination conditions. After filling all the placeholders, the filled contract terms are packaged and standardized according to the smart contract encapsulation format specified by the blockchain network. Then, the encapsulated contract template is submitted to the blockchain network for deployment. During the deployment process, the compliance of the contract format and the integrity of the logic are verified. After successful verification, the initial contract instance of the first smart contract is generated. This instance has executable contract logic and complete transaction information.
[0149] The self-consistency verification rules of the contract logic built into the first smart contract are invoked. These rules clearly state that the logical relationships between contract terms must be verified to be consistent, the execution conditions must be met, and the state transitions must conform to the preset process. According to these verification rules, all contract terms of the initial contract instance are logically verified item by item. During the verification process, it is checked whether the electricity and electricity price information in the transaction terms match the data traceability information in the execution logic, whether the default handling terms correspond to the transaction terms, and whether the termination conditions are compatible with the state transition logic in the execution logic. After the verification is passed, the state field of the initial contract instance is updated from the initial state to the pending execution state according to the state update rules of the first smart contract. During the update process, the timestamp and operation identifier of the state update are recorded. After the update is completed, the pending execution smart contract instance of the first smart contract is obtained. This instance has complete contract content, valid participant addresses, compliant logical structure, and pending execution state identifier, and can be triggered for execution by the blockchain network.
[0150] By clearly defining the criteria for determining the electricity demand and supply values, the smaller of the two values is selected as the baseline value for electricity matching. This provides an accurate and practical benchmark for subsequent priority determination, avoiding matching deviations caused by an unreasonable benchmark. Based on this baseline value, a Gaussian kernel mapping is applied to the absolute value of the price difference between the intended electricity purchase and sale prices. This incorporates the degree of electricity matching and the price difference into a comprehensive consideration, accurately quantifying the matching priority factor and clarifying the priority of the pairing candidates. By arranging the factors in descending order to form a priority ranking sequence, and combining this with an updated matching threshold, the matching candidates that meet the priority requirements are selected sequentially from the first position in the sequence, resulting in the matching pair entries for the first smart contract. The entire process is clear in its steps, specific in its judgment criteria, and highly reproducible. It effectively solves the problems of ambiguous matching priority determination and inaccurate matching results, ensuring that the matching pair entries align with the actual needs of microgrid electricity purchase and sale transactions, improving the rationality and accuracy of transaction matching, and providing a reliable matching foundation for subsequent contract arrangement and transaction execution.
[0151] The initial contract instance undergoes sentence-by-sentence contract syntax parsing, verifying the expression standards, logical statements, and format completeness of each contract clause, and checking for grammatical errors, clause conflicts, and other issues. Simultaneously, the contract virtual machine of the blockchain network is invoked, and the syntax parsing results are input into the contract virtual machine. The contract virtual machine then verifies each instruction in the parsing results against a preset instruction set whitelist, confirming that all instructions are within the whitelist and that there are no non-compliant instructions. Upon successful verification, a syntax pass identifier is generated. This identifier serves as a clear pass credential, proving that the initial contract instance's syntax is compliant. This entire process is manually traceable, with no black-box operations, ensuring that the syntax parsing and verification process is reproducible.
[0152] After confirming that the initial contract instance has no grammatical errors based on the syntax pass flag, the agreed-upon electricity value is extracted from the initial contract instance. Simultaneously, the electricity demand and supply values from the orchestration parameter set are retrieved. The agreed-upon electricity value of the initial contract instance is compared one by one with the electricity demand and supply values to determine if there is a contradiction. If the agreed-upon electricity value does not exceed either the electricity demand or supply value, the mutual exclusion is approved, and an electricity constraint verification pass result is generated. If the agreed-upon electricity value exceeds either value, the verification fails, and an electricity constraint verification failure result is generated. This result is the electricity constraint verification result of the first smart contract.
[0153] Based on the electricity constraint verification results, if the verification passes, the payment terms and agreed electricity values in the initial contract instance are further checked. According to the pricing standards agreed upon by the electricity purchaser and seller, the correspondence between the payment amount and the agreed electricity value is checked one by one to confirm that the amount calculation in the payment terms matches the agreed electricity value and there is no calculation deviation. The value stream verification is completed, and a logical self-consistency verification mark is generated after calibration. If the electricity constraint verification fails, the value stream verification is not performed, and no logical self-consistency verification mark is generated to ensure that the logical self-consistency verification mark only corresponds to the initial contract instance that meets the electricity constraint requirements.
[0154] Based on the logical self-consistency verification identifier, it is confirmed that the initial contract instance has grammatical compliance, meets the electricity constraints, and the payment terms match the agreed electricity value. Then, according to the preset state update rules, the state field of the initial contract instance is changed from "initial state" to "pending execution" state. Key information such as the time of state change and operation node are recorded synchronously. After the state update is completed, the first smart contract pending execution smart contract instance is formed. This instance can be directly used for subsequent contract execution operations, ensuring seamless connection with the previous electricity purchase and sale matching process and contract orchestration process.
[0155] By parsing the initial contract instance sentence by sentence and verifying it against the instruction set whitelist, syntax errors and non-compliant instructions can be accurately identified, generating clear syntax compliance markers to ensure contract syntax compliance and traceability, preventing contract execution failures due to syntax issues. By comparing the agreed-upon electricity value in the initial contract instance with the purchased and sold electricity amounts, mutual exclusion criteria are clarified, generating electricity constraint verification results to ensure consistency between the contract's electricity terms and actual transaction needs, preventing transaction disputes caused by electricity mismatches. By verifying the correspondence between payment terms and agreed-upon electricity values, value stream verification is completed, generating logical self-consistency verification markers to ensure logical coherence and consistency of contract terms. Finally, the contract status is updated to pending execution, forming a compliant pending execution smart contract instance. This ensures the standardization and reliability of contract execution, seamlessly integrates with the previous electricity purchase and sale matching and contract orchestration processes, improves contract execution efficiency, and provides solid support for the orderly development of microgrid electricity purchase and sale transactions.
[0156] In step 6, the settlement data of the second smart contract is obtained, including:
[0157] The actual power generation value and actual load power value in the actual execution data of microgrid nodes are separated from the agreed power value by removing the difference, and the result of the actual execution data is obtained.
[0158] The deviation power value and deviation direction identifier of the stripping result are aggregated to obtain the deviation identification result of the second smart contract;
[0159] Based on the deviation identification results and the deviation settlement logic built into the second smart contract, the settlement path is confirmed for the deviation direction identifier and the deviation power value to obtain the deviation settlement amount of the second smart contract.
[0160] Based on the deviation settlement amount and the participant account addresses of the smart contract instance to be executed, fund transfer instructions are assembled for the payer account and payee account identified by the deviation direction to obtain the settlement data of the second smart contract.
[0161] Extract the actual power generation value, actual load power value, and agreed power value from the actual execution data of the microgrid nodes, as well as the agreed power value in the smart contract instance to be executed. Compare the actual power generation value with the agreed power value and the actual load power value with the agreed power value one by one, and extract the difference between the two as the deviation. Clarify the specific value and positive or negative direction of the deviation. A positive value indicates that the actual value is higher than the agreed value, and a negative value indicates that the actual value is lower than the agreed value. Compile and summarize all the deviations and their corresponding directions to obtain the extraction result of the actual execution data.
[0162] The deviation power values and deviation direction identifiers in the stripping results are classified and collected. The deviation direction corresponding to each deviation value is checked one by one. The deviation power values are classified according to the deviation direction identifier. Data with a value of 0 and no deviation are removed. Only the entries with deviation are retained to form a complete deviation detail. This detail is the deviation identification result of the second smart contract.
[0163] The deviation settlement logic built into the second smart contract is invoked. This logic sets clear settlement standards based on the deviation direction identifier and the deviation power value. First, the settlement rules corresponding to the deviation direction identifier are confirmed. If the deviation is higher than the agreed value, the deduction is made according to the established standard. If the deviation is lower than the agreed value, the compensation is made according to the established standard. Then, the specific settlement method and amount are determined by combining the specific size of the deviation power value, and the settlement path is confirmed. Finally, the deviation settlement amount of the second smart contract is obtained.
[0164] Extract the participant account addresses recorded in the smart contract instance to be executed, clarify the account information of the electricity purchaser and seller, and determine the payer and payee accounts for fund transfer by combining the deviation settlement amount and deviation direction identifier. When the deviation is positive, the electricity seller is the payee and the electricity purchaser is the payer; when the deviation is negative, the electricity purchaser is the payee and the electricity seller is the payer. Assemble the fund transfer instruction according to the standard format of blockchain transactions. The instruction clearly specifies the transfer amount, the account addresses of both parties, and the transfer time. This instruction is the settlement data of the second smart contract.
[0165] By performing sentence-by-sentence grammatical analysis and clause-by-clause verification on initial contract instances, grammatical compliance standards are clarified, and traceable grammatical compliance markers are generated to ensure that the contract syntax is standardized and free of logical loopholes, preventing contract execution failures due to grammatical errors. Accurate verification of electricity quantities by both the buyer and seller clarifies electricity constraint standards, effectively avoiding disputes caused by electricity quantity mismatches and ensuring smooth transaction progress. Value stream calibration and logical self-consistency verification ensure that contract terms are consistent with actual transaction needs, reducing execution deviations. By updating the contract status to a pending execution state, standardized pending contract instances are formed, achieving seamless integration with the previous electricity purchase and sale matching and contract orchestration processes, improving contract execution efficiency, and clarifying the traceability of contract execution. This provides reliable support for the orderly conduct of microgrid electricity purchase transactions, ensuring a standardized transaction process, verifiable results, and enhancing the overall security and rationality of the transaction.
[0166] In step 7, the stored settlement records of the second smart contract are obtained, including:
[0167] The settlement data is serialized and assembled into a transaction payload, and the notarization transaction body is generated for the notarization interface of the second smart contract to obtain the notarization transaction to be submitted for the second smart contract.
[0168] The transaction to be submitted for evidence storage is signed with a private key, and the signed transaction is broadcast to the transaction pool to obtain the broadcast transaction identifier of the blockchain network;
[0169] The status of the block production of broadcast transaction identifiers is polled and monitored to obtain on-chain transaction receipts from the blockchain network;
[0170] Based on the on-chain transaction receipts, ABI decoding is performed on the contract event logs of the on-chain transaction receipts to extract the stored settlement records of the second smart contract.
[0171] The settlement data is extracted to contain five core pieces of information: deviation settlement amount, participant account address, deviation direction identifier, notarized transaction hash, and settlement timestamp. Following the transaction payload serialization format specified by the blockchain network, this information is structured, encapsulated, and binary encoded according to a preset field order. After serialization and assembly, the notarization interface pre-configured by the second smart contract is called. The serialized payload data is passed in according to the interface's input parameter specifications. The notarization interface then performs format verification, field completion, and standardized encapsulation on the payload data according to the smart contract's notarized transaction body generation logic, generating a complete notarized transaction body containing the contract address, transaction parameters, and event signature. This transaction body is the notarized transaction to be submitted by the second smart contract.
[0172] Obtain the private key of the operator bound to the second smart contract. Use this private key to perform an asymmetric cryptographic signature operation on the hash value of the transaction body of the transaction to be submitted for notarization. During the operation, follow the signature specifications of the elliptic curve digital signature algorithm to generate a unique transaction signature value and append it to the end of the transaction to be submitted for notarization. After the signature is completed, broadcast the complete transaction containing the signature information to the transaction pool through the peer-to-peer network protocol of the blockchain network. The transaction pool nodes perform preliminary verification of the signature validity, balance adequacy and format compliance of the transaction. After the verification is passed, a unique transaction identifier is assigned to the transaction. This identifier is the broadcast transaction identifier of the blockchain network.
[0173] According to the preset polling listening rules, a fixed polling time interval and a maximum number of polling times are set. Using the broadcast transaction identifier as the search keyword, a transaction receipt query request is periodically initiated to the node interface of the blockchain network. During the query process, the format of the returned data is verified to conform to the receipt specifications of the blockchain network, and the transaction identifier is checked to ensure consistency. The process continues until a blockchain-on-chain transaction receipt containing the transaction hash, block height, packaging node identifier, and on-chain timestamp is obtained, or the maximum number of polling times is reached and the listening is terminated. This receipt is the blockchain-on-chain transaction receipt.
[0174] Obtain the predefined application binary interface specification of the second smart contract. This interface clarifies the field types, arrangement order, and decoding rules of the contract event log. According to the interface specification, perform binary data parsing on the contract event log in the on-chain transaction receipt, match the event signature and field type in the log one by one, complete the deserialization and field extraction of the log data, and extract core information such as settlement amount, participant account, deviation direction, notarized transaction hash, and on-chain block number. Integrate and standardize the storage according to the preset record structure to form the notarized settlement record of the second smart contract containing complete settlement information and traceability fields.
[0175] By parsing the initial contract instance sentence by sentence and verifying it against the instruction set whitelist using the contract virtual machine, syntax errors and non-compliant instructions are accurately identified, generating a syntax pass flag to ensure contract syntax compliance and traceability, preventing contract execution failures due to syntax issues. Based on the syntax pass flag, the agreed electricity value is compared with the purchased and sold electricity amounts one by one, clarifying the mutual exclusion criteria and generating electricity constraint verification results to prevent transaction disputes caused by electricity mismatch. Based on the electricity constraint verification results, the correspondence between payment terms and agreed electricity values is checked, value stream verification is completed, and a logical self-consistency verification flag is generated to ensure the logical coherence and consistency of contract terms. Finally, the contract status is updated to pending execution, forming a standardized pending execution smart contract instance, achieving seamless integration with the previous process, improving contract execution efficiency, ensuring the standardization and reliability of microgrid electricity purchase and sale contract execution, and providing solid support for the orderly conduct of transactions.
[0176] To adapt to high-concurrency power trading scenarios in microgrids and avoid network congestion, high gas fees, and processing delays caused by end-to-end on-chain notarization, a layered notarization and batch on-chain optimization mechanism is adopted, based on end-to-end on-chain notarization: Transaction intention entries, matching intermediate data, and other process information can be stored in IPFS or a distributed database for off-chain caching. They are then batch-packaged in fixed time windows or fixed transaction numbers. After generating a single Merkle root hash for all data in the batch, only this hash value is notarized on the blockchain. The blockchain only retains the hash digest to ensure data credibility and traceability, while the original detailed data is stored off-chain. At the same time, high-frequency execution logic such as transaction matching, contract execution, and deviation settlement can be run on the consortium blockchain sidechain, while the main chain only stores the final settlement certificate. Under the premise of ensuring transaction credibility, traceability, and immutability, this significantly reduces the on-chain transaction concurrency and storage pressure, and improves the operating performance in high-concurrency scenarios.
[0177] A simulation diagram of the dynamic load and matching performance of the smart contract for power trading in microgrids is shown below. Figure 2 As shown, the horizontal axis represents time (unit: hours), the left vertical axis represents the dynamic load factor L (i.e., the current dynamic load factor L, dimensionless), and the right vertical axis represents the matching threshold (%) and matching efficiency (%). Figure 2 The blue curve represents the dynamic load coefficient L, which fluctuates over time within the range of 0.4 to 1.0, reflecting the real-time load changes of the blockchain network. The red line represents the matching threshold that is dynamically adjusted according to the load. During periods of abnormally high load (around 40-60 hours and 150 hours), the matching threshold is increased synchronously to retain only high-priority matching pairs and reduce concurrent inflows to avoid further network congestion. The matching efficiency recovers rapidly after a brief decrease, indicating that the dynamic threshold adaptive mechanism of the method in this embodiment can balance the stability of transaction matching and overall matching efficiency under network load fluctuations.
[0178] The algorithm involved in this embodiment can be executed by an electronic device, which includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The algorithm described above is implemented by executing the program through the processor.
[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for micro-electricity trading based on blockchain smart contracts, characterized by the following steps: include: Step 1: Perform time-series extrapolation analysis on the historical operating data of microgrid nodes and the electricity price configuration data of distribution network nodes to obtain the predicted operating data of microgrid nodes and the predicted electricity price time-series values of distribution network nodes; Step 2: Compare the power purchase and sale surplus of the predicted operating data and the predicted electricity price time series value, and decompose the obtained surplus results based on the preset electricity price gradient to obtain the transaction intention items of the microgrid nodes. Step 3: Digest the transaction intention entries, and store the resulting hash digests and transaction intention entries on the blockchain to obtain the on-chain transaction intention records of the microgrid nodes; Step 4: Based on the first smart contract on the blockchain network, traverse and match the on-chain transaction intention records, and dynamically and adaptively adjust the matching threshold of the first smart contract based on the load status of the blockchain network to obtain the matching pairs of the first smart contract. Step 5: Based on the first smart contract, perform contract orchestration on the matching entries to obtain the smart contract instance to be executed for the first smart contract; Step 6: Based on the second smart contract on the blockchain network, perform deviation settlement between the actual execution data of the microgrid node and the smart contract instance to be executed to obtain the settlement data of the second smart contract; Step 7: Write the settlement data into the blockchain network to obtain the stored settlement record of the second smart contract.
2. The method for micro-electricity trading based on blockchain smart contracts as described in claim 1, characterized in that, In step 1, the predicted operating data of microgrid nodes and the predicted electricity price time series values of distribution network nodes are obtained, including: Periodic features are extracted from the historical power generation sequence of microgrid nodes to obtain the power generation trend feature value of microgrid nodes, and fluctuation feature decomposition is performed on the historical load power sequence of microgrid nodes to obtain the load fluctuation feature components of microgrid nodes. Based on the characteristic values of power generation trends and the characteristic components of load fluctuations, time-series trend fitting is performed on the power generation and load power of microgrid nodes during the forecast period to obtain the predicted operating data of microgrid nodes. The electricity price fluctuation cycle is identified by analyzing the historical time-of-use electricity price series to obtain the electricity price fluctuation cycle parameters of the distribution network nodes; Based on the electricity price fluctuation cycle parameter, the electricity price changes within the prediction period are time-series mapped to obtain the predicted electricity price time-series values for distribution network nodes.
3. The method for micro-electricity trading based on blockchain smart contracts as described in claim 1, characterized in that, In step 2, the transaction intention entries of the microgrid nodes are obtained, including: The predicted power generation and predicted load power values in the predicted operation data are used to determine the power surplus, and the power surplus status value of the microgrid node is obtained. The surplus status value of electricity and the predicted electricity price point value in the predicted electricity price time series value are combined and matched to obtain the surplus result entries of the microgrid nodes. The preset electricity price gradient is decomposed to obtain the electricity price range of the preset electricity price gradient, and the predicted electricity price point value in the surplus result item is assigned to the electricity price range to obtain the intention label of the electricity price range. By associating and integrating the power surplus status value and the intention tag, the transaction intention entries of the microgrid node are obtained.
4. The method for micro-electricity trading based on blockchain smart contracts as described in claim 1, characterized in that, In step 3, the on-chain transaction intention records of the microgrid nodes are obtained, including: Key domains are extracted from the transaction intention entries to obtain the transaction intention data to be summarized for each transaction intention entry; Based on the hash generation interface on the blockchain network, the transaction intention data to be digested is cryptographically hashed to obtain the hash digest returned by the hash generation interface; Based on the blockchain network transaction data encapsulation format, the hash digest is associated with the transaction intention entry to obtain the transaction data package to be uploaded to the blockchain of the microgrid node, and the transaction data package is submitted to the evidence storage smart contract on the blockchain network to obtain the evidence storage transaction hash returned by the evidence storage smart contract. Based on the hash of the evidence storage transaction, the evidence storage result of the evidence storage smart contract is parsed to obtain the on-chain transaction intention record of the microgrid node.
5. The method for micro-electricity trading based on blockchain smart contracts as described in claim 1, characterized in that, In step 4, the matching entries for the first smart contract are obtained, including: Based on the first smart contract on the blockchain network, the on-chain transaction intention records are filtered and collected to obtain the microgrid node's transaction intention dataset to be matched. The purchase intention and sale intention of electricity in the dataset of transaction intentions to be matched are matched and identified. Based on the timestamp field of the on-chain transaction intention record, the matching identification results are merged by time to obtain the initial matching candidate set of the first smart contract. The dynamic load coefficient of the first smart contract is obtained by dynamically calculating the current number of pending transactions and the current block generation interval of the blockchain network: ; Where L represents the current dynamic load factor, N represents the current number of transactions pending processing, N0 represents the baseline number of transactions pending processing, T represents the current block generation interval, and T0 represents the baseline block generation interval. This represents the difference between the current number of pending transactions and the number of pending transactions at the previous time. This represents the instantaneous load weighting coefficient. This represents the processing efficiency weighting coefficient. Indicates the load change weighting coefficient; Based on the current dynamic load coefficient and the preset baseline threshold, the matching threshold of the first smart contract is located by key value to obtain the update matching threshold of the first smart contract. Based on the updated matching threshold and the initial matching candidate set, the initial matching candidate set is prioritized. When the matching priority meets the updated matching threshold, the matching pair of the first smart contract is obtained.
6. The method for micro-electricity trading based on blockchain smart contracts as described in claim 5, characterized in that, Prioritize the initial matching candidate set. When the matching priority meets the update matching threshold, obtain the matching pair entry for the first smart contract. The specific process is as follows: The smaller value between the electricity demand value of the intended electricity purchase and the electricity supply value is used as the electricity matching base value of the first smart contract; Based on the electricity matching baseline, a Gaussian kernel mapping is applied to the absolute value of the difference between the intended electricity price for purchasing and the intended electricity price for selling, to obtain the matching priority factor of the initial matching candidate set. The Gaussian kernel mapping calculation formula is as follows: ; S is the matching priority factor; the larger the value, the higher the priority. This is the absolute difference between the intended purchase price and the intended sale price of electricity. As the base value for battery power matching, Gaussian kernel bandwidth; Based on the matching priority factor, the matching candidate pairs in the initial matching candidate set are sorted in descending order to obtain the priority ranking sequence of electricity purchase intentions; Based on the priority sorting sequence and the updated matching threshold, the priority sorting sequence is selected in ascending order to obtain the matching pair entries of the first smart contract.
7. The method for micro-electricity trading based on blockchain smart contracts as described in claim 1, characterized in that, In step 5, the instance of the first smart contract to be executed is obtained, including: Based on the matching entries, attribute access is performed on the matching entries to obtain the orchestration parameter set of the first smart contract; The power purchase microgrid node identifiers and power sales microgrid node identifiers in the parameter set are used to map the contract participant addresses, and on-chain identity queries are performed on the blockchain network to obtain the participant address pairs of the first smart contract. Based on the participant address pairs and the orchestration parameter set, placeholders are filled into the contract terms of the preset smart contract template, and the filled contract terms are encapsulated and deployed to obtain the initial contract instance of the first smart contract. The initial contract instance is logically self-consistent, and its state field is updated to the pending execution state to obtain the pending execution smart contract instance of the first smart contract.
8. The method for micro-electricity trading based on blockchain smart contracts as described in claim 7, characterized in that, The initial contract instance is logically self-consistent, and its state field is updated to a pending execution state to obtain the first smart contract instance to be executed. The specific process is as follows: The initial contract instance is parsed using contract syntax, and the parsing result of the initial contract instance is verified using an instruction set whitelist based on the contract virtual machine of the blockchain network to obtain the syntax pass mark of the first smart contract. Based on the syntax and the identifier, the mutual exclusion of the agreed electricity value of the initial contract instance with the electricity demand value and the electricity supply value in the orchestration parameter set is determined, and the electricity constraint verification result of the first smart contract is obtained. Based on the power constraint verification results, the payment terms and agreed power values in the initial contract instance are verified by value stream verification to obtain the logical self-consistency verification identifier of the first smart contract. Based on the logical self-consistency verification identifier, the state field of the initial contract instance is changed from the initial state to the pending execution state, thus obtaining the pending execution smart contract instance of the first smart contract.
9. The method for micro-electricity trading based on blockchain smart contracts as described in claim 8, characterized in that, In step 6, the settlement data of the second smart contract is obtained, including: The actual power generation value and actual load power value in the actual execution data of microgrid nodes are separated from the agreed power value by removing the difference, and the result of the actual execution data is obtained. The deviation power value and deviation direction identifier of the stripping result are aggregated to obtain the deviation identification result of the second smart contract; Based on the deviation identification results and the deviation settlement logic built into the second smart contract, the settlement path is confirmed by the deviation direction identifier and the deviation power value to obtain the deviation settlement amount of the second smart contract. Based on the deviation settlement amount and the participant account addresses of the smart contract instance to be executed, fund transfer instructions are assembled for the payer account and payee account identified by the deviation direction to obtain the settlement data of the second smart contract.
10. The method for micro-electricity trading based on blockchain smart contracts as described in claim 1, characterized in that, In step 7, the stored settlement records of the second smart contract are obtained, including: The settlement data is serialized and assembled into a transaction payload, and the notarization transaction body is generated for the notarization interface of the second smart contract to obtain the notarization transaction to be submitted for the second smart contract. The transaction to be submitted for evidence storage is signed with a private key, and the signed transaction is broadcast to the transaction pool to obtain the broadcast transaction identifier of the blockchain network; The status of the block production of broadcast transaction identifiers is polled and monitored to obtain on-chain transaction receipts from the blockchain network; Based on the on-chain transaction receipts, ABI decoding is performed on the contract event logs of the on-chain transaction receipts to extract the stored settlement records of the second smart contract.
Citation Information
Patent Citations
Block chain-based micro-grid distributed energy transaction method and system
CN113643131A
Node information updating method in multi-virtual power plant interaction scene based on block chain
CN117499047A