Grayscale upgrade method and device for smart contracts in blockchain, and electronic equipment
By deploying and managing smart contracts on the blockchain, managing smart contract reception and processing smart contract call transactions, the problem of incompatibility in smart contract grayscale upgrades in the blockchain is solved, and stable grayscale upgrades and business execution are achieved.
Patent Information
- Application Number
- CN202210473056.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-29
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2042-04-29
AI Technical Summary
There are incompatibility problems with the grayscale upgrade of smart contracts in blockchain, which may affect normal business execution during the upgrade process, and it is difficult for the existing technology to effectively manage and execute grayscale upgrades.
By deploying management smart contracts on the blockchain, receiving smart contract calls transactions initiated by the initiator, and adding running environment tags to the transactions, determining whether the transaction is a test transaction related to grayscale upgrades, thereby calling new and old versions across the contract Business smart contracts execute transactions.
It realizes the stable grayscale upgrade of smart contracts in the blockchain, avoids the problems of incompatibility during the upgrade process, ensures the stability of business execution, and effectively manages the grayscale upgrade process.
Smart Images

Figure CN114780123B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a grayscale upgrade method and device, and electronic device for smart contracts in a blockchain. Background Art
[0002] Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Blockchain technology has been widely used in many fields because of its decentralized, open and transparent characteristics, each computing device can participate in database records, and data can be quickly synchronized between computing devices. Summary of the invention
[0003] The embodiments of this specification provide a method and device for grayscale upgrading of smart contracts in a blockchain, and an electronic device.
[0004] According to a first aspect of an embodiment of this specification, a method for grayscale upgrading a smart contract in a blockchain is provided, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of a business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrading management of the business smart contract; the method comprises:
[0005] Receiving a smart contract call transaction initiated by a call initiator for the business smart contract;
[0006] In response to the smart contract call transaction, adding an operating environment tag indicating the type of the software operating environment of the call initiator to the smart contract call transaction;
[0007] The smart contract call transaction with the operating environment tag added is sent to the node device in the blockchain, so that the node device responds to the smart contract call transaction, calls the management smart contract deployed on the blockchain, determines whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag, and when it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; otherwise, further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
[0008] Optionally, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0009] The step of adding an operating environment tag indicating the type of the software operating environment of the call initiator to the smart contract call transaction includes:
[0010] Determining the software operating environment of the call initiator;
[0011] If the determined software operating environment is a pre-release environment, adding a pre-release environment tag indicating that the software operating environment is a pre-release environment to the smart contract call transaction initiated by the call initiator;
[0012] If the determined software operating environment is a grayscale release environment, adding a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the smart contract call transaction initiated by the call initiator;
[0013] If the determined software operating environment is a production environment, a production environment tag indicating that the software operating environment is a production environment is added to the smart contract call transaction initiated by the call initiator.
[0014] Optionally, before receiving the smart contract call transaction initiated by the call initiator for the business smart contract, the method further includes:
[0015] Obtain the contract code of the new version of the business smart contract;
[0016] Construct a smart contract creation transaction containing the contract code, and send the smart contract creation transaction to the node device in the blockchain, so that the node device executes the smart contract creation, creates the new version of the business smart contract in the blockchain based on the contract code, and completes the deployment of the new version of the business smart contract.
[0017] Optionally, the method further includes:
[0018] In response to the new version of the business smart contract being deployed on the blockchain, the current software operating environment is switched to the pre-release environment.
[0019] Optionally, if the software operating environment is a pre-release environment, the method further includes:
[0020] Obtaining the execution result of the smart contract call transaction from the node device;
[0021] Based on the execution result, determine whether the new version of the business smart contract passes the pre-release test corresponding to the pre-release stage; if so, switch the current software running environment from the pre-release environment to the grayscale release environment.
[0022] Optionally, if the software operating environment is a grayscale release environment, the method further includes:
[0023] Obtaining the execution result of the smart contract call transaction from the node device;
[0024] Based on the execution result, determine whether the new version of the business smart contract passes the grayscale release test corresponding to the grayscale release stage; if so, switch the current software running environment from the grayscale release environment to the production environment.
[0025] According to a second aspect of an embodiment of this specification, a method for grayscale upgrading a smart contract in a blockchain is provided, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of a business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrading management of the business smart contract; the method comprises:
[0026] Receiving a smart contract call transaction initiated by a call initiator for the business smart contract; wherein the smart contract call transaction includes an operating environment tag indicating the type of the software operating environment of the call initiator;
[0027] In response to the smart contract call transaction, call the management smart contract deployed on the blockchain, and determine whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag;
[0028] If it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0029] Optionally, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0030] The determining, based on the operating environment tag, whether the smart contract call transaction is a test transaction related to the grayscale upgrade includes:
[0031] Determine the type of the operating environment tag carried by the smart contract call transaction;
[0032] If the operating environment tag carried by the smart contract call transaction is a pre-release environment tag, determining that the smart contract call transaction is a pre-release test transaction related to the pre-release stage;
[0033] If the running environment tag carried by the smart contract call transaction is a grayscale environment tag, determining that the smart contract call transaction is a grayscale release test transaction related to the grayscale release stage;
[0034] If the operating environment tag carried by the smart contract call transaction is a generated environment tag, or the smart contract call transaction does not carry the operating environment tag, it is determined that the smart contract call transaction is not a test transaction related to the grayscale upgrade.
[0035] Optionally, the management smart contract maintains a traffic diversion strategy for the smart contract call transaction;
[0036] Among them, in the pre-release stage for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release stage, call the new version of the business smart contract to execute the smart contract call transaction; otherwise, call the old version of the business smart contract to execute the smart contract call transaction;
[0037] If it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further cross-contract call the new version of the business smart contract to execute the smart contract call transaction; otherwise, further cross-contract call the old version of the business smart contract to execute the smart contract call transaction, including:
[0038] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0039] Optionally, in the phase of grayscale release for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release phase; or a grayscale release test transaction related to the grayscale release phase, calling the new version of the business smart contract to execute the smart contract call transaction; otherwise, calling the old version of the business smart contract to execute the smart contract call transaction;
[0040] If it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further cross-contract call the new version of the business smart contract to execute the smart contract call transaction; otherwise, further cross-contract call the old version of the business smart contract to execute the smart contract call transaction, including:
[0041] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage; or, a grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0042] Optionally, the method further includes:
[0043] Receiving an upgrade request for the business smart contract initiated by a call initiator when the business smart contract passes a pre-release test corresponding to the pre-release stage; wherein the upgrade request includes a call parameter for instructing the traffic diversion strategy maintained by the management smart contract to be switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the grayscale release stage;
[0044] In response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameters, the traffic diversion strategy is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the grayscale release stage.
[0045] Optionally, the method further includes:
[0046] Receive an upgrade request for the business smart contract initiated by a call initiator when the business smart contract passes the grayscale release test corresponding to the grayscale release stage; wherein the upgrade request includes a call parameter for instructing the traffic diversion strategy maintained by the management smart contract to be switched from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed;
[0047] In response to the upgrade request, the strategy switching logic included in the management smart contract is called, and based on the call parameters, the traffic diversion strategy is switched from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed, so as to complete the grayscale upgrade for the business smart contract;
[0048] Among them, the traffic diversion strategy after the grayscale upgrade is completed includes: calling the new version of the business smart contract by default to execute the smart contract call transaction.
[0049] Optionally, the method further includes:
[0050] Receiving a rollback request for the business smart contract initiated by a call initiator when the business smart contract fails the pre-release test or the grayscale release test; wherein the rollback request includes a call parameter for instructing to switch the traffic diversion strategy maintained by the management smart contract to a default traffic diversion strategy;
[0051] In response to the rollback request, calling the strategy switching logic included in the management smart contract, and switching the traffic diversion strategy to a default traffic diversion strategy based on the calling parameters;
[0052] Among them, the default traffic diversion strategy includes: calling the old version of the business smart contract by default to execute the smart contract call transaction.
[0053] According to a third aspect of an embodiment of this specification, a grayscale upgrade device for a smart contract in a blockchain is provided, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of a business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the device comprises:
[0054] A transaction receiving unit, receiving a smart contract call transaction initiated by a call initiator for the business smart contract;
[0055] a label adding unit, in response to the smart contract call transaction, adding an operating environment label indicating the type of the software operating environment of the call initiator to the smart contract call transaction;
[0056] The grayscale upgrade unit sends the smart contract call transaction with the operating environment tag added to the node device in the blockchain, so that the node device responds to the smart contract call transaction, calls the management smart contract deployed on the blockchain, determines whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag, and when it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; otherwise, further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
[0057] Optionally, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0058] The label adding unit includes:
[0059] Determine a subunit to determine the software operating environment of the call initiator;
[0060] A first adding subunit, if the determined software operating environment is a pre-release environment, adds a pre-release environment tag indicating that the software operating environment is a pre-release environment to the smart contract call transaction initiated by the call initiator;
[0061] A second adding subunit, if the determined software operating environment is a grayscale release environment, adds a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the smart contract call transaction initiated by the call initiator;
[0062] The third adding subunit adds a production environment tag indicating that the software operating environment is a production environment to the smart contract call transaction initiated by the call initiator if the determined software operating environment is a production environment.
[0063] Optionally, before the transaction receiving unit, it also includes:
[0064] The contract deployment unit obtains the contract code of the new version of the business smart contract; constructs a smart contract creation transaction containing the contract code, and sends the smart contract creation transaction to the node device in the blockchain, so that the node device executes the smart contract creation, and creates the new version of the business smart contract in the blockchain based on the contract code to complete the deployment of the new version of the business smart contract.
[0065] Optionally, the device further comprises:
[0066] The environment switching unit switches the current software running environment to the pre-release environment in response to the new version of the business smart contract being deployed on the blockchain.
[0067] Optionally, if the software operating environment is a pre-release environment, the device further includes:
[0068] A result judgment unit obtains the execution result of the smart contract call transaction from the node device; determines whether the new version of the business smart contract passes the pre-release test corresponding to the pre-release stage based on the execution result; if so, switches the current software running environment from the pre-release environment to the grayscale release environment.
[0069] Optionally, if the software operating environment is a grayscale release environment, the device further includes:
[0070] A result judgment unit obtains the execution result of the smart contract call transaction from the node device; determines whether the new version of the business smart contract passes the grayscale release test corresponding to the grayscale release stage based on the execution result; if so, switches the current software running environment from the grayscale release environment to the production environment.
[0071] According to a fourth aspect of the embodiments of this specification, a grayscale upgrade device for a smart contract in a blockchain is provided, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of a business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the device comprises:
[0072] A transaction receiving unit, receiving a smart contract call transaction initiated by a call initiator for the business smart contract; wherein the smart contract call transaction includes an operating environment tag indicating the type of the software operating environment of the call initiator;
[0073] A contract calling unit, in response to the smart contract calling transaction, calls a management smart contract deployed on the blockchain, and determines whether the smart contract calling transaction is a test transaction related to the grayscale upgrade based on the operating environment tag;
[0074] The grayscale upgrade unit, if it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; otherwise, further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
[0075] Optionally, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0076] The contract calling unit includes:
[0077] A determination subunit determines the type of the operating environment tag carried by the smart contract call transaction; if the operating environment tag carried by the smart contract call transaction is a pre-release environment tag, the smart contract call transaction is determined to be a pre-release test transaction related to the pre-release stage; if the operating environment tag carried by the smart contract call transaction is a grayscale environment tag, the smart contract call transaction is determined to be a grayscale release test transaction related to the grayscale release stage; if the operating environment tag carried by the smart contract call transaction is a generated environment tag, or the smart contract call transaction does not carry the operating environment tag, it is determined that the smart contract call transaction is not a test transaction related to the grayscale upgrade.
[0078] Optionally, the management smart contract maintains a traffic diversion strategy for the smart contract call transaction;
[0079] Among them, in the pre-release stage for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release stage, call the new version of the business smart contract to execute the smart contract call transaction; otherwise, call the old version of the business smart contract to execute the smart contract call transaction;
[0080] The grayscale upgrading unit comprises:
[0081] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0082] Optionally, in the phase of grayscale release for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release phase; or a grayscale release test transaction related to the grayscale release phase, calling the new version of the business smart contract to execute the smart contract call transaction; otherwise, calling the old version of the business smart contract to execute the smart contract call transaction;
[0083] The grayscale upgrading unit comprises:
[0084] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage; or, a grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0085] Optionally, the device further comprises:
[0086] A first strategy switching unit receives an upgrade request for the business smart contract initiated by a call initiator when the business smart contract passes a pre-release test corresponding to the pre-release stage; wherein the upgrade request includes a call parameter for indicating that the traffic diversion strategy maintained by the management smart contract is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the gray release stage; in response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameter, the traffic diversion strategy is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the gray release stage.
[0087] Optionally, the device further comprises:
[0088] The second strategy switching unit receives an upgrade request for the business smart contract initiated by the call initiator when the business smart contract passes the grayscale release test corresponding to the grayscale release stage; wherein the upgrade request includes a call parameter for indicating that the drainage strategy maintained by the management smart contract is switched from the drainage strategy of the grayscale release stage to the drainage strategy after the grayscale upgrade is completed; in response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameter, the drainage strategy is switched from the drainage strategy of the grayscale release stage to the drainage strategy after the grayscale upgrade is completed, so as to complete the grayscale upgrade for the business smart contract; wherein the drainage strategy after the grayscale upgrade is completed includes: calling the new version of the business smart contract by default to execute the smart contract call transaction.
[0089] Optionally, the device further comprises:
[0090] The third strategy switching unit receives a rollback request for the business smart contract initiated by the call initiator when the business smart contract fails the pre-release test or the grayscale release test; wherein the rollback request includes a call parameter for indicating that the traffic diversion strategy maintained by the management smart contract is switched to a default traffic diversion strategy; in response to the rollback request, the strategy switching logic contained in the management smart contract is called, and the traffic diversion strategy is switched to a default traffic diversion strategy based on the call parameter; wherein the default traffic diversion strategy includes: calling the old version of the business smart contract by default to execute the smart contract call transaction.
[0091] According to a fifth aspect of the embodiments of this specification, an electronic device is provided, including:
[0092] processor;
[0093] a memory for storing processor-executable instructions;
[0094] Wherein, the processor is configured as any of the above-mentioned grayscale upgrade methods for smart contracts in the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0095] Figure 1 It is a flowchart of a blockchain transaction execution method provided in an embodiment of this specification;
[0096] Figure 2 It is a flow chart of a grayscale upgrade method of a smart contract in a blockchain provided in an embodiment of this specification;
[0097] Figure 3 It is a flow chart of a grayscale upgrade method of a smart contract in a blockchain provided in an embodiment of this specification;
[0098] Figure 4 It is a flow chart of a grayscale upgrade method of a blockchain service platform provided in an embodiment of this specification;
[0099] Figure 5 It is a flow chart of a grayscale upgrade method of a blockchain service platform provided in an embodiment of this specification;
[0100] Figure 6 is a hardware structure diagram of a device provided in an embodiment of this specification;
[0101] Figure 7 It is a module diagram of a blockchain transaction execution device provided in an embodiment of this specification;
[0102] Figure 8 It is a module schematic diagram of a grayscale upgrade device for a smart contract in a blockchain provided in an embodiment of this specification;
[0103] Fig. 9 It is a module schematic diagram of a grayscale upgrade device for a smart contract in a blockchain provided in an embodiment of this specification;
[0104] Fig.10 It is a module schematic diagram of a grayscale upgrade device of a blockchain service platform provided in an embodiment of this specification;
[0105] Fig.11 It is a module diagram of a grayscale upgrade device of a blockchain service platform provided in an embodiment of this specification. DETAILED DESCRIPTION
[0106] Exemplary embodiments are described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.
[0107] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms of "a", "said" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more associated listed items. Multiple in this article can refer to two or more situations.
[0108] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0109] In related technologies, grayscale upgrade refers to a smooth transition upgrade method. In the grayscale upgrade process for blockchain, A / B testing is first used, that is, some users continue to use the old version of the blockchain; some users start to use the new version of the blockchain; if users have no objection to the new version, then gradually expand the scope of use of the new version and slowly migrate all users to the new version.
[0110] The grayscale upgrade method can ensure the stability of the entire blockchain. Problems can be discovered and handled in a timely manner in the initial grayscale stage. Since the user group in the initial grayscale stage is small, even if problems occur, the impact range is limited.
[0111] In practical applications, the blockchain needs to perceive the grayscale changes of the blockchain for blockchain transactions initiated by the transaction initiator, so as to use the new and old versions of the grayscale changes to execute blockchain transactions initiated by different users.
[0112] This specification aims to provide a method for adding corresponding operating environment tags to blockchain transactions according to the software operating environment of the transaction initiator without the need to perceive the grayscale changes of the blockchain, so that the node devices of the blockchain can execute blockchain transactions based on the software operating environment determined by the operating environment tags.
[0113] Please refer to the following Figure 1 , Figure 1 A blockchain transaction execution method provided in this specification can be applied to an access program corresponding to a blockchain; the method may include the following steps:
[0114] Step 110: In response to a blockchain transaction initiated by a transaction initiator, determine the software operating environment of the transaction initiator.
[0115] Step 120: Based on the determined software operating environment, adding an operating environment tag indicating the type of the software operating environment of the transaction initiator to the blockchain transaction;
[0116] Step 130: Send the blockchain transaction with the operating environment tag added to the node device in the blockchain, so that the node device responds to the blockchain transaction, determines the software operating environment of the transaction initiator based on the operating environment tag, and executes the blockchain transaction based on the determined software operating environment.
[0117] In this specification, the access program may include an SDK access program integrated on a blockchain service platform. The blockchain service platform may include a BaaS platform (also referred to as a BaaS cloud) for providing blockchain as a service (BaaS, Blockchain as a Service). Among them, the BaaS platform can provide easy-to-use, one-click deployment, fast verification, and flexible and customizable blockchain services for user client-side computing devices coupled to the BaaS platform by providing pre-written software for activities occurring on the blockchain (such as subscriptions and notifications, user verification, database management, and remote updates), thereby accelerating the development, testing, and launch of blockchain business applications and helping the implementation of blockchain business application scenarios in various industries.
[0118] During implementation, the transaction initiator can initiate a blockchain transaction to the blockchain service platform through a user client, add an operating environment tag to the blockchain transaction through an access program on the blockchain service platform, and send the blockchain transaction with the added operating environment tag to the node device in the blockchain.
[0119] In one embodiment, the software operating environment of the transaction initiator maintains operating parameters corresponding to the software operating environment;
[0120] The determining of the software operating environment of the transaction initiator includes:
[0121] The operating parameters maintained in the software operating environment are read, and the type of the software operating environment of the transaction initiator is determined based on the read operating parameters.
[0122] In this specification, the operating parameters may be sent to the access program together with the blockchain transaction, so that the access line can read the operating parameters maintained in the software operating environment, and then determine the type of the software operating environment of the transaction initiator based on the read operating parameters.
[0123] In addition, the operating parameters may also be the operating parameters that the access program requests from the transaction initiator after receiving the blockchain transaction.
[0124] In this specification, the access program can determine the software operating environment of the transaction initiator by using the operating parameters corresponding to the software operating environment maintained in the software operating environment of the transaction initiator.
[0125] In one embodiment, the value of the operating parameter is used to indicate the type of the software operating environment; wherein the value of the operating parameter is synchronously updated when the software operating environment is switched;
[0126] The determining the type of the software operating environment of the transaction initiator based on the read operating parameters includes:
[0127] The type of the software operating environment of the transaction initiator is determined based on the read value of the operating parameter.
[0128] In this specification, different values of the operating parameters may correspond to different types of software operating environments, which may include a pre-release environment, a grayscale release environment, a production environment, and the like.
[0129] In this specification, the operating parameters include environment variables for indicating the type of the software operating environment.
[0130] In one embodiment, a smart contract for identifying a software operating environment is deployed on the blockchain;
[0131] The determining the type of the software operating environment of the transaction initiator based on the read operating parameters includes:
[0132] Submitting the read operating parameters as calling parameters to the smart contract to call the identification logic contained in the smart contract, and identifying the type of the software operating environment of the transaction initiator based on the operating parameters;
[0133] Obtain an identification result of the smart contract for the type of the software operating environment, and determine the type of the software operating environment of the transaction initiator based on the identification result.
[0134] In this specification, the identifying the type of the software operating environment of the transaction initiator based on the operating parameters may include analyzing the operating parameters and identifying based on the rules satisfied by the operating parameters; or maintaining a list or array in the smart contract to record the correspondence between the operating parameters and the types of software operating environments, and then identifying the type of the software operating environment corresponding to the operating parameters based on this correspondence.
[0135] In one embodiment, the blockchain transaction includes a test transaction related to the grayscale upgrade. For example, the blockchain transaction includes a test transaction related to the grayscale upgrade of a business smart contract deployed on the blockchain; or the blockchain transaction includes a test transaction related to the grayscale upgrade of the transaction processing logic supported by each node device on the blockchain.
[0136] Take the test transaction related to the grayscale upgrade of the business smart contract deployed on the blockchain as an example.
[0137] The blockchain generally provides the function of smart contracts. Smart contracts on the blockchain are contracts that can be triggered and executed by blockchain transactions. Smart contracts can be defined in the form of code. By writing the execution logic of specific business into business smart contracts in the form of code and publishing them to the blockchain, various complex business logics can be implemented on the blockchain.
[0138] Since the execution logic of the business will continue to change with the development of the business, there is also a need to upgrade the business smart contract. However, due to the immutable nature of the blockchain, the business smart contract that has been published on the blockchain cannot be modified; therefore, upgrading the business smart contract is not a simple modification of the contract code, but a new version of the business smart contract (including the upgraded business logic) needs to be released, and then the business smart contract in effect in the blockchain is switched to the new version of the business smart contract to invalidate the old version of the business smart contract.
[0139] In actual applications, due to the incompatibility issues that may exist during the upgrade of business smart contracts, if all business smart contracts in the blockchain are switched to the new version, once the new version is incompatible with the old version, it will affect the execution of normal business. Based on this, the grayscale upgrade for business smart contracts came into being. The grayscale upgrade method can ensure the stability of the blockchain where the business smart contracts are deployed. Problems can be discovered and handled in a timely manner in the initial grayscale stage. Since the user group in the initial grayscale stage is small, even if problems occur, the impact range is limited.
[0140] Since the blockchain deploys both old and new versions of business smart contracts, it is necessary to sense whether the blockchain transaction initiated by the transaction initiator is a test transaction related to the grayscale upgrade, and call the corresponding business smart contract to execute the blockchain transaction.
[0141] Specifically, in this specification, the blockchain deploys an old version of the business smart contract before the grayscale upgrade, a new version of the business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract;
[0142] Accordingly, in response to the blockchain transaction, the step 130 determines the software operating environment of the transaction initiator based on the operating environment tag, and executes the blockchain transaction based on the determined software operating environment, including:
[0143] In response to the blockchain transaction, the management smart contract deployed on the blockchain is called, and based on the operating environment tag, it is determined whether the blockchain transaction is a test transaction related to the grayscale upgrade of the business smart contract deployed on the blockchain. If so, the new version of the business smart contract is further called across contracts to execute the blockchain transaction; if not, the old version of the business smart contract is further called across contracts to execute the blockchain transaction.
[0144] In this specification, a management smart contract is deployed on the blockchain to manage the calls of the old and new versions of the business smart contract, so that the grayscale test of the business smart contract can be completed under the management of the management smart contract.
[0145] To better illustrate the implementation of test transactions related to grayscale upgrades of business smart contracts deployed on the blockchain, please refer to the following example: Figure 2 As shown, this specification provides a method for grayscale upgrade of smart contracts in a blockchain, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade, a new version of a business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the method includes:
[0146] Step 210: Receive a smart contract call transaction initiated by a call initiator for the business smart contract.
[0147] In this embodiment, the call initiator corresponds to the aforementioned Figure 1 The transaction initiator in the smart contract call transaction corresponds to the aforementioned Figure 1 In addition, with Figure 1 Same, Figure 2 The illustrated embodiment is applied to an access procedure corresponding to a blockchain.
[0148] In addition, the access program may also be an SDK access program on a user client that is directly connected to the blockchain.
[0149] Step 220: In response to the smart contract call transaction, add an operating environment tag indicating the type of the software operating environment of the call initiator to the smart contract call transaction.
[0150] In this specification, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0151] Accordingly, in step 220, adding an operating environment tag indicating the type of the software operating environment of the call initiator to the smart contract call transaction includes:
[0152] Determining the software operating environment of the call initiator;
[0153] If the determined software operating environment is a pre-release environment, adding a pre-release environment tag indicating that the software operating environment is a pre-release environment to the smart contract call transaction initiated by the call initiator;
[0154] If the determined software operating environment is a grayscale release environment, adding a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the smart contract call transaction initiated by the call initiator;
[0155] If the determined software running environment is a production environment; or, the production environment tag indicating that the software running environment is a production environment is not added to the smart contract call transaction initiated by the call initiator in the software running environment, then the production environment tag indicating that the software running environment is a production environment is added to the smart contract call transaction initiated by the call initiator.
[0156] In this specification, determining the software operating environment of the call initiator may be the same as determining the software operating environment of the transaction initiator in the aforementioned step 110, and will not be described in detail here.
[0157] In this manual, the grayscale upgrade process can be to first perform a pre-release (corresponding to the pre-release environment), complete the pre-release test, and switch to the grayscale release environment; then perform a grayscale release (corresponding to the grayscale release environment), complete the grayscale release test, and then switch to the production environment.
[0158] Step 230, sending the smart contract call transaction with the operating environment tag added to the node device in the blockchain, so that the node device responds to the smart contract call transaction, calls the management smart contract deployed on the blockchain, and determines whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag, and when it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; otherwise, further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
[0159] In this specification, the test transactions related to the grayscale upgrade may include pre-release test transactions and grayscale test transactions. Accordingly, in the pre-release stage, the smart contract call transaction carrying the pre-release mark is a test transaction; in the grayscale release stage, the smart contract call transaction carrying the pre-release mark and the grayscale release mark is a test transaction; for the test transaction, the new version of the business smart contract can be further called across contracts to execute the smart contract call transaction; if it is not a test transaction, the old version of the business smart contract can be further called across contracts to execute the smart contract call transaction.
[0160] In implementation, the blockchain can expose the contract address of the management smart contract to the user, so that the user does not know the existence of the business smart contract. In this way, although the smart contract call transaction initiated by the user carries the contract address of the management smart contract, it is actually used to call the business smart contract.
[0161] This is also the reason why, in this manual, although the access program receives a smart contract call transaction for a business smart contract, it calls the management smart contract by default; and after the node device responds to the smart contract call transaction, it first calls the management smart contract based on the contract address of the management smart contract, and then further calls the new or old version of the business smart contract through a cross-contract call.
[0162] In one embodiment, before step 210, the method further includes:
[0163] Obtain the contract code of the new version of the business smart contract;
[0164] Construct a smart contract creation transaction containing the contract code, and send the smart contract creation transaction to the node device in the blockchain, so that the node device executes the smart contract creation, creates the new version of the business smart contract in the blockchain based on the contract code, and completes the deployment of the new version of the business smart contract.
[0165] This example provides a way to deploy a new version of a business smart contract in the blockchain, thereby starting a grayscale upgrade for the business smart contract in the blockchain.
[0166] In one embodiment, the access program can switch the current software operating environment to the pre-release environment in response to the new version of the business smart contract being deployed on the blockchain.
[0167] In this specification, after the new version of the business smart contract is deployed, the access program will trigger a switch request for the software operating environment to switch the current software operating environment to the pre-release environment. The switching of the current software operating environment to the pre-release environment can be implemented by directly switching the database.
[0168] In this manual, the grayscale upgrade process can be to first perform a pre-release (corresponding to the pre-release environment), complete the pre-release test, and switch to the grayscale release environment; then perform a grayscale release (corresponding to the grayscale release environment), complete the grayscale release test, and then switch to the production environment.
[0169] In one embodiment, if the software operating environment is a pre-release environment, the method further includes:
[0170] Obtaining the execution result of the smart contract call transaction from the node device;
[0171] Based on the execution result, determine whether the new version of the business smart contract passes the pre-release test corresponding to the pre-release stage; if so, switch the current software running environment from the pre-release environment to the grayscale release environment.
[0172] In this specification, the access program can analyze the execution results of the pre-release test transactions to determine whether the execution results meet the test expectations; if so, it is determined that the new version of the business smart contract has passed the pre-release test corresponding to the pre-release stage, which means that the pre-release test is completed. At this time, the current software running environment can be switched from the pre-release environment to the grayscale release environment, so as to carry out the next stage of grayscale release.
[0173] In one embodiment, if the software operating environment is a grayscale release environment, the method further includes:
[0174] Obtaining the execution result of the smart contract call transaction from the node device;
[0175] Based on the execution result, determine whether the new version of the business smart contract passes the grayscale release test corresponding to the grayscale release stage; if so, switch the current software running environment from the grayscale release environment to the production environment.
[0176] In this specification, the access program can analyze the execution results of the grayscale release test transactions to determine whether the execution results meet the test expectations; if they do, it is determined that the new version of the business smart contract has passed the grayscale release test corresponding to the grayscale release stage, which means that the grayscale release test is completed. At this time, the current software running environment can be switched from the grayscale release environment to the production environment to enter the production stage.
[0177] Through the above embodiments, this specification aims to define a standard process for grayscale testing of business smart contracts for grayscale upgrades.
[0178] By deploying a management smart contract on the blockchain, the calls of the old and new versions of the business smart contracts can be managed, so that the grayscale testing of the business smart contracts can be completed under the management of the management smart contract.
[0179] This manual also provides corresponding Figure 2 An embodiment of the method with a node device of a blockchain as an execution subject, wherein the blockchain deploys an old version of a business smart contract before a grayscale upgrade, a new version of a business smart contract after a grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the embodiment, for example Figure 3 Shown include:
[0180] Step 310: Receive a smart contract call transaction initiated by a call initiator for the business smart contract; wherein the smart contract call transaction includes an operating environment tag indicating the type of the software operating environment of the call initiator.
[0181] Step 320: In response to the smart contract call transaction, call the management smart contract deployed on the blockchain, and determine whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag.
[0182] In one embodiment, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0183] Accordingly, determining whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag in 320 includes:
[0184] Determine the type of the operating environment tag carried by the smart contract call transaction;
[0185] If the operating environment tag carried by the smart contract call transaction is a pre-release environment tag, determining that the smart contract call transaction is a pre-release test transaction related to the pre-release stage;
[0186] If the running environment tag carried by the smart contract call transaction is a grayscale environment tag, determining that the smart contract call transaction is a grayscale release test transaction related to the grayscale release stage;
[0187] If the operating environment tag carried by the smart contract call transaction is a generated environment tag, or the smart contract call transaction does not carry the operating environment tag, it is determined that the smart contract call transaction is not a test transaction related to the grayscale upgrade.
[0188] This example is similar to the previous Figure 2 The specific details can be referred to the above examples, which will not be described here.
[0189] Step 330: If it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0190] In this specification, the management smart contract maintains a traffic diversion strategy for the smart contract call transaction.
[0191] In the pre-release stage for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release stage, calling the new version of the business smart contract to execute the smart contract call transaction; otherwise, calling the old version of the business smart contract to execute the smart contract call transaction;
[0192] The corresponding step 330 includes:
[0193] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0194] In addition, in the phase of grayscale release of the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release phase; or a grayscale release test transaction related to the grayscale release phase, call the new version of the business smart contract to execute the smart contract call transaction; otherwise, call the old version of the business smart contract to execute the smart contract call transaction;
[0195] The corresponding step 330 includes:
[0196] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage; or, a grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0197] In one embodiment, the node device may also receive an upgrade request for the business smart contract initiated by the call initiator when the business smart contract passes the pre-release test corresponding to the pre-release stage; wherein the upgrade request may include a call parameter for instructing the traffic diversion strategy maintained by the management smart contract to be switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the grayscale release stage;
[0198] In response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameters, the traffic diversion strategy is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the grayscale release stage.
[0199] In this specification, an upgrade request can be a request data or a smart contract call transaction for the above-mentioned management smart contract.
[0200] In one embodiment, the node device may receive an upgrade request for the business smart contract initiated by the call initiator when the business smart contract passes the grayscale release test corresponding to the grayscale release stage; wherein the upgrade request includes a call parameter for instructing the traffic diversion strategy maintained by the management smart contract to be switched from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed;
[0201] In response to the upgrade request, the strategy switching logic included in the management smart contract is called, and based on the call parameters, the traffic diversion strategy is switched from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed, so as to complete the grayscale upgrade for the business smart contract;
[0202] In this specification, the traffic diversion strategy after the grayscale upgrade is completed includes: calling the new version of the business smart contract by default to execute the smart contract call transaction.
[0203] The diversion strategy is a mapping relationship between the type of the operating environment label and the new version or old version of the business smart contract.
[0204] In one embodiment, the node device receives a rollback request for the business smart contract initiated by a call initiator when the business smart contract fails the pre-release test or the grayscale release test; wherein the rollback request includes a call parameter for indicating that the traffic diversion strategy maintained by the management smart contract is switched to a default traffic diversion strategy;
[0205] In response to the rollback request, calling the strategy switching logic included in the management smart contract, and switching the traffic diversion strategy to a default traffic diversion strategy based on the calling parameters;
[0206] In this specification, the default traffic diversion strategy includes: calling the old version of the business smart contract by default to execute the smart contract call transaction.
[0207] Through the above embodiments, this specification aims to define a standard process for grayscale testing of business smart contracts for grayscale upgrades.
[0208] By deploying a management smart contract on the blockchain, the calls of the old and new versions of the business smart contracts can be directed and managed, so that the grayscale testing of the business smart contracts can be completed under the management of the management smart contract.
[0209] After introducing the above implementation example of the test transaction related to the grayscale upgrade of the business smart contract deployed on the blockchain, let us return to Figure 1 The illustrated embodiment further introduces an embodiment of a test transaction related to the grayscale upgrade of the transaction processing logic supported by each node device on the blockchain.
[0210] In this specification, the transaction processing logic supported by at least some node devices in the blockchain is replaced with the new version of the transaction processing logic after the grayscale upgrade;
[0211] Accordingly, in response to the blockchain transaction, the step 130 determines the software operating environment of the transaction initiator based on the operating environment tag, and executes the blockchain transaction based on the determined software operating environment, including:
[0212] In response to the blockchain transaction, it is determined based on the operating environment tag whether the blockchain transaction is a test transaction related to the grayscale upgrade of the transaction processing logic supported by each node device on the blockchain. If so, the test transaction is forwarded to the node device supporting the new version of the transaction processing logic for transaction processing; if not, the test transaction is forwarded to the node device supporting the old version of the transaction processing logic for transaction processing.
[0213] In this specification, a solution for grayscale upgrade of the transaction processing logic of node devices is provided. By testing the transaction processing logic of node devices to ensure that the new version of the transaction processing logic is executed correctly, grayscale upgrade of node devices in the blockchain is achieved.
[0214] To better illustrate the implementation of the test transaction related to the grayscale upgrade of the transaction processing logic supported by each node device on the blockchain, please refer to the following example: Figure 4 As shown, this specification provides a grayscale upgrade method for a blockchain service platform, in which the transaction processing logic supported by at least some node devices in the blockchain managed by the blockchain service platform is replaced with a new version of the transaction processing logic after the grayscale upgrade; the method includes:
[0215] Step 410: Receive a blockchain transaction initiated by a transaction initiator.
[0216] In this embodiment, the call initiator corresponds to the aforementioned Figure 1 In addition, Figure 1 akin, Figure 4 The illustrated embodiment is applied to an access program for docking with a blockchain, and the access program is integrated into a blockchain service platform.
[0217] Step 420: In response to the blockchain transaction, add an operating environment tag indicating the type of the software operating environment of the transaction initiator to the blockchain transaction.
[0218] In this specification, the transaction initiator may send a request carrying an operating environment tag to the blockchain service platform, which is then packaged into a blockchain transaction by the blockchain service platform.
[0219] Of course, what the transaction initiator sends to the blockchain service platform can also be a packaged blockchain transaction carrying an operating environment tag.
[0220] In this specification, the grayscale upgrade for the blockchain service platform includes: a pre-release phase for the transaction execution logic of the new version; and a grayscale release phase after the pre-release phase is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release phase, and a grayscale release environment corresponding to the grayscale release phase;
[0221] Accordingly, in step 420, adding an operating environment tag indicating the type of the software operating environment to the blockchain transaction initiated by the transaction initiator includes:
[0222] Determining the software operating environment of the transaction initiator;
[0223] If the determined software operating environment is a pre-release environment, adding a pre-release environment tag indicating that the software operating environment is a pre-release environment to the blockchain transaction initiated by the transaction initiator;
[0224] If the determined software operating environment is a grayscale release environment, adding a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the blockchain transaction initiated by the transaction initiator;
[0225] If the determined software operating environment is a production environment, a production environment tag indicating that the software operating environment is a production environment is added to the blockchain transaction initiated by the transaction initiator; alternatively, the production environment tag is not added to the blockchain transaction initiated by the transaction initiator in the software operating environment.
[0226] In this specification, determining the software operating environment of the transaction initiator may be the same as determining the software operating environment of the transaction initiator in the aforementioned step 110, and will not be described in detail here.
[0227] In this manual, the grayscale upgrade process can be to first perform a pre-release (corresponding to the pre-release environment), complete the pre-release test, and switch to the grayscale release environment; then perform a grayscale release (corresponding to the grayscale release environment), complete the grayscale release test, and then switch to the production environment.
[0228] In one embodiment, before step 410, the method further includes:
[0229] In response to a notification message issued by the blockchain service platform that the transaction processing logic supported by at least some node devices in the blockchain is replaced with a new version of the transaction processing logic after the grayscale upgrade, the current software operating environment is switched to the pre-release environment.
[0230] This example provides a pre-release process for grayscale upgrade of some node devices in the blockchain.
[0231] In one embodiment, if the software operating environment is a pre-release environment, the method further includes:
[0232] In response to a notification message issued by the blockchain service platform that the new version of the transaction processing logic has passed the pre-release test, the current software operating environment is switched from the pre-release environment to the grayscale environment.
[0233] In one embodiment, if the software operating environment is a grayscale environment, the method further includes:
[0234] In response to a notification message issued by the blockchain service platform that the new version of the transaction processing logic has passed the grayscale release test, the current software running environment is switched from the grayscale release environment to the production environment.
[0235] It should be noted that Figure 2 The difference between the grayscale upgrade of smart contracts shown in the figure is that during the grayscale upgrade of smart contracts, the action of judging whether the test has passed is performed by the access program, while in this example, the action of judging whether the test has passed is performed by the blockchain during the grayscale upgrade of the transaction processing logic supported by the node device; the access program only needs to complete the switching of the software running environment according to the notification message fed back by the blockchain.
[0236] Step 430: Send the blockchain transaction with the operating environment tag added to the blockchain, so that the blockchain responds to the blockchain transaction, determines whether the blockchain transaction is a test transaction related to the grayscale upgrade based on the operating environment tag, and when it is determined that the blockchain transaction is a test transaction related to the grayscale upgrade, forwards the test transaction to a node device that supports the new version of the transaction processing logic for transaction processing; otherwise, forwards the test transaction to a node device that supports the old version of the transaction processing logic for transaction processing.
[0237] Through the above embodiments, this specification aims to define a standard process for grayscale testing of transaction processing logic supported by node devices of blockchain.
[0238] By adding an operating environment tag to the blockchain transaction to indicate the type of software operating environment of the transaction initiator, the blockchain can determine whether the blockchain transaction is a test transaction based on the operating environment tag. If it is, the transaction is processed by a node device that supports the new version of the transaction processing logic; otherwise, the transaction is processed by a node device that supports the old version of the transaction processing logic. In this way, the grayscale upgrade of node devices in the blockchain can be achieved.
[0239] This manual also provides corresponding Figure 4In an embodiment of the method with a node device of a blockchain as the execution subject, the transaction processing logic supported by at least some node devices in the blockchain managed by the blockchain service platform is replaced with a new version of the transaction processing logic after the grayscale upgrade; the embodiment, for example Figure 5 Shown include:
[0240] Step 510: Receive a blockchain transaction initiated by a transaction initiator; wherein the blockchain transaction includes an operating environment tag indicating the type of the software operating environment of the transaction initiator.
[0241] Step 520: In response to the blockchain transaction, determine whether the blockchain transaction is a test transaction related to the grayscale upgrade based on the operating environment tag.
[0242] In one embodiment, the grayscale upgrade for the blockchain service platform includes: a pre-release phase for the transaction execution logic of the new version; and a grayscale release phase after the pre-release phase is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release phase, and a grayscale release environment corresponding to the grayscale release phase;
[0243] Accordingly, determining whether the blockchain transaction is a test transaction related to the grayscale upgrade based on the operating environment tag in step 520 includes:
[0244] Determining the type of the operating environment tag carried by the blockchain transaction;
[0245] If the operating environment tag carried by the blockchain transaction is a pre-release environment tag, determining that the blockchain transaction is a pre-release test transaction related to the pre-release stage;
[0246] If the operating environment tag carried by the blockchain transaction is a grayscale environment tag, determining that the blockchain transaction is a grayscale release test transaction related to the grayscale release stage;
[0247] If the operating environment tag carried by the blockchain transaction is a generation environment tag, or the blockchain transaction does not carry the operating environment tag, it is determined that the blockchain transaction is not a test transaction related to the grayscale upgrade.
[0248] This example is similar to the previous Figure 2 The specific details can be referred to the above examples, which will not be described here.
[0249] Step 530: If it is determined that the blockchain transaction is a test transaction related to the grayscale upgrade, the test transaction is forwarded to a node device that supports the new version of the transaction processing logic for transaction processing; otherwise, the test transaction is forwarded to a node device that supports the old version of the transaction processing logic for transaction processing.
[0250] In this specification, the blockchain service platform maintains a traffic diversion strategy for the blockchain transactions.
[0251] In the pre-release phase for the new version of the transaction processing logic, the traffic diversion strategy includes: if the blockchain transaction is a pre-release test transaction related to the pre-release phase, forwarding the test transaction to a node device supporting the new version of the transaction processing logic for transaction processing; otherwise, forwarding the test transaction to a node device supporting the old version of the transaction processing logic for transaction processing;
[0252] The corresponding step 530 includes:
[0253] If it is determined that the blockchain transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the node device supporting the new version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the new version of the transaction processing logic for transaction processing; otherwise, the node device supporting the old version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the old version of the transaction processing logic for transaction processing.
[0254] In addition, in the phase of grayscale release of the transaction processing logic of the new version, the traffic diversion strategy includes: if the blockchain transaction is a pre-release test transaction related to the pre-release phase; or a grayscale release test transaction related to the grayscale release phase, forwarding the test transaction to a node device supporting the new version of the transaction processing logic for transaction processing; otherwise, forwarding the test transaction to a node device supporting the old version of the transaction processing logic for transaction processing;
[0255] The corresponding step 530 includes:
[0256] If it is determined that the blockchain transaction is a pre-release test transaction related to the pre-release stage; or, a grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, the node device supporting the new version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the new version of the transaction processing logic for transaction processing; otherwise, the node device supporting the old version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the old version of the transaction processing logic for transaction processing.
[0257] In this specification, the diversion strategy is a mapping relationship between the type of the operating environment tag and the transaction processing execution of the new version or the old version.
[0258] In one embodiment, the node device can also increase the grayscale upgrade range of the node devices in the blockchain in sequence based on a preset grayscale upgrade progress, and replace the binary code corresponding to the transaction processing logic supported by the node devices within the grayscale upgrade range with the binary code corresponding to the new version of the transaction processing logic in sequence.
[0259] In this specification, grayscale upgrade of node devices generally involves adding new processing logic while ensuring that the basic blockchain processing logic (such as consensus logic) supported by the node devices remains unchanged; for example, a new transaction type is added to the blockchain.
[0260] In one embodiment, the method may further include:
[0261] Obtaining the execution result of the blockchain transaction from the node device;
[0262] Determine whether the new version of the transaction processing logic has passed the pre-release test corresponding to the pre-release stage based on the execution result; if yes, send a notification message to the transaction initiator that the new version of the transaction processing logic has passed the pre-release test; and
[0263] Based on the execution result, determine whether the new version of the transaction processing logic has passed the grayscale release test corresponding to the grayscale release stage; if so, send a notification message to the transaction initiator that the new version of the transaction processing logic has passed the grayscale release test.
[0264] In this specification, the execution results of the pre-release or grayscale release test transactions are analyzed to determine whether the execution results meet the test expectations; if they meet the expectations, it is determined that the new version of the transaction processing logic has passed the pre-release test or grayscale release test, so that a notification message that the new version of the transaction processing logic has passed the pre-release test or grayscale release test can be sent to the transaction initiator, so that the transaction initiator switches its software operating environment. For example, when passing the pre-release test, the transaction initiator switches the software operating environment from the pre-release environment to the grayscale release environment; or, when passing the grayscale release test, the transaction initiator switches the software operating environment from the grayscale release environment to the production environment.
[0265] In one embodiment, the method may further include:
[0266] In response to the new version of the transaction processing logic passing the pre-release test, switching the traffic diversion strategy from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the phased release stage; and,
[0267] In response to the new version of the transaction processing logic passing the grayscale release test, switching the traffic diversion strategy from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed;
[0268] Among them, the traffic diversion strategy after the grayscale upgrade is completed includes: forwarding the blockchain transaction to the node device that supports the new version of the transaction processing logic for transaction processing by default.
[0269] In addition, if the new version of the transaction execution logic fails the pre-release test or the grayscale release test, it may also include:
[0270] In response to the new version of the transaction execution logic failing the pre-release test or the phased release test, switching the traffic diversion strategy to a default traffic diversion strategy;
[0271] Among them, the default traffic diversion strategy includes: forwarding the blockchain transaction to a node device that supports the old version of the transaction processing logic for transaction processing by default.
[0272] Through the above embodiments, this specification aims to define a standard process for grayscale testing of transaction processing logic supported by node devices of blockchain. And, through the traffic diversion strategy maintained by the blockchain service platform, traffic is diverted for blockchain transactions, thereby completing grayscale testing of transaction processing logic supported by node devices of blockchain.
[0273] Corresponding to the above method embodiments, this specification also provides corresponding device embodiments. The device embodiments can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the device in which it is located reading the corresponding computer business program instructions in the non-volatile memory into the memory for execution. From the hardware level, such as Figure 6 The figure is a hardware structure diagram of the device provided in this manual, except Figure 6 In addition to the processor, network interface, memory and non-volatile memory shown, the device in which the apparatus in the embodiment is located may also include other hardware according to actual functions, which will not be described in detail.
[0274] See also Figure 7 , is a module diagram of a blockchain transaction execution device provided in an embodiment of this specification, and the device corresponds to Figure 1 The embodiment shown is applied to an access program corresponding to a blockchain, and the device includes:
[0275] A determination unit 710, in response to a blockchain transaction initiated by a transaction initiator, determines a software operating environment of the transaction initiator;
[0276] An adding unit 720 adds an operating environment tag indicating the type of the software operating environment of the transaction initiator to the blockchain transaction based on the determined software operating environment;
[0277] The execution unit 730 sends the blockchain transaction with the operating environment tag added to the node device in the blockchain, so that the node device responds to the blockchain transaction, determines the software operating environment of the transaction initiator based on the operating environment tag, and executes the blockchain transaction based on the determined software operating environment.
[0278] Optionally, the software operating environment of the transaction initiator maintains operating parameters corresponding to the software operating environment;
[0279] The determining unit 710 includes:
[0280] The reading subunit reads the operating parameters maintained in the software operating environment, and determines the type of the software operating environment of the transaction initiator based on the read operating parameters.
[0281] Optionally, the value of the operating parameter is used to indicate the type of the software operating environment; wherein the value of the operating parameter is synchronously updated when the software operating environment is switched;
[0282] The reading subunit comprises:
[0283] The type of the software operating environment of the transaction initiator is determined based on the read value of the operating parameter.
[0284] Optionally, the operating parameters include environment variables for indicating the type of the software operating environment.
[0285] Optionally, a smart contract for identifying the software operating environment is deployed on the blockchain;
[0286] The reading subunit comprises:
[0287] The calling subunit submits the read operating parameters as calling parameters to the smart contract to call the identification logic contained in the smart contract, and identifies the type of the software operating environment of the transaction initiator based on the operating parameters;
[0288] The acquisition subunit obtains the identification result of the smart contract for the type of the software operating environment, and determines the type of the software operating environment of the transaction initiator based on the identification result.
[0289] Optionally, the blockchain transaction includes a test transaction related to the grayscale upgrade.
[0290] Optionally, the blockchain transaction includes a test transaction related to a grayscale upgrade of a business smart contract deployed on the blockchain; or, the blockchain transaction includes a test transaction related to a grayscale upgrade of a transaction processing logic supported by each node device on the blockchain.
[0291] Optionally, the blockchain deploys an old version of the business smart contract before the grayscale upgrade, a new version of the business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract;
[0292] The execution unit 730 is further used to call the management smart contract deployed on the blockchain in response to the blockchain transaction, and determine whether the blockchain transaction is a test transaction related to the grayscale upgrade of the business smart contract deployed on the blockchain based on the operating environment tag; if so, further call the new version of the business smart contract across contracts to execute the blockchain transaction; if not, further call the old version of the business smart contract across contracts to execute the blockchain transaction.
[0293] Optionally, the transaction processing logic supported by at least some of the node devices in the blockchain is replaced with a new version of the transaction processing logic after the grayscale upgrade;
[0294] The execution unit 730 is further used to respond to the blockchain transaction and determine, based on the operating environment tag, whether the blockchain transaction is a test transaction related to the grayscale upgrade of the transaction processing logic supported by each node device on the blockchain; if so, forward the test transaction to the node device supporting the new version of the transaction processing logic for transaction processing; if not, forward the test transaction to the node device supporting the old version of the transaction processing logic for transaction processing.
[0295] See also Figure 8 , is a module diagram of a grayscale upgrade device for a smart contract in a blockchain provided in an embodiment of this specification, and the device corresponds to Figure 2 In the embodiment shown, the blockchain deploys an old version of the business smart contract before the grayscale upgrade, a new version of the business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the device includes:
[0296] The transaction receiving unit 810 receives a smart contract call transaction initiated by a call initiator for the business smart contract;
[0297] A label adding unit 820, in response to the smart contract call transaction, adds an operating environment label indicating the type of the software operating environment of the call initiator to the smart contract call transaction;
[0298] The grayscale upgrade unit 830 sends the smart contract call transaction with the operating environment tag added to the node device in the blockchain, so that the node device responds to the smart contract call transaction, calls the management smart contract deployed on the blockchain, and determines whether the smart contract call transaction is a test transaction related to the grayscale upgrade based on the operating environment tag. When it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0299] Optionally, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0300] The label adding unit 820 includes:
[0301] Determine a subunit to determine the software operating environment of the call initiator;
[0302] A first adding subunit, if the determined software operating environment is a pre-release environment, adds a pre-release environment tag indicating that the software operating environment is a pre-release environment to the smart contract call transaction initiated by the call initiator;
[0303] A second adding subunit, if the determined software operating environment is a grayscale release environment, adds a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the smart contract call transaction initiated by the call initiator;
[0304] The third adding subunit adds a production environment tag indicating that the software operating environment is a production environment to the smart contract call transaction initiated by the call initiator if the determined software operating environment is a production environment.
[0305] Optionally, before the transaction receiving unit 810, it further includes:
[0306] The contract deployment unit obtains the contract code of the new version of the business smart contract; constructs a smart contract creation transaction containing the contract code, and sends the smart contract creation transaction to the node device in the blockchain, so that the node device executes the smart contract creation, and creates the new version of the business smart contract in the blockchain based on the contract code to complete the deployment of the new version of the business smart contract.
[0307] Optionally, the device further comprises:
[0308] The environment switching unit switches the current software running environment to the pre-release environment in response to the new version of the business smart contract being deployed on the blockchain.
[0309] Optionally, if the software operating environment is a pre-release environment, the device further includes:
[0310] A result judgment unit obtains the execution result of the smart contract call transaction from the node device; determines whether the new version of the business smart contract passes the pre-release test corresponding to the pre-release stage based on the execution result; if so, switches the current software running environment from the pre-release environment to the grayscale release environment.
[0311] Optionally, if the software operating environment is a grayscale release environment, the device further includes:
[0312] A result judgment unit obtains the execution result of the smart contract call transaction from the node device; determines whether the new version of the business smart contract passes the grayscale release test corresponding to the grayscale release stage based on the execution result; if so, switches the current software running environment from the grayscale release environment to the production environment.
[0313] See also Fig. 9 , is a module diagram of a grayscale upgrade device for a smart contract in a blockchain provided in an embodiment of this specification, and the device corresponds to Figure 3 In the embodiment shown, the blockchain deploys an old version of the business smart contract before the grayscale upgrade, a new version of the business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the device includes:
[0314] The transaction receiving unit 910 receives a smart contract call transaction initiated by a call initiator for the business smart contract; wherein the smart contract call transaction includes an operating environment tag indicating the type of the software operating environment of the call initiator;
[0315] The contract calling unit 920 calls the management smart contract deployed on the blockchain in response to the smart contract calling transaction, and determines whether the smart contract calling transaction is a test transaction related to the grayscale upgrade based on the operating environment tag;
[0316] The grayscale upgrade unit 930, if it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; otherwise, further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
[0317] Optionally, the grayscale upgrade for the business smart contract includes a pre-release stage for the new version of the business smart contract; and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage;
[0318] The contract calling unit 920 includes:
[0319] A determination subunit determines the type of the operating environment tag carried by the smart contract call transaction; if the operating environment tag carried by the smart contract call transaction is a pre-release environment tag, the smart contract call transaction is determined to be a pre-release test transaction related to the pre-release stage; if the operating environment tag carried by the smart contract call transaction is a grayscale environment tag, the smart contract call transaction is determined to be a grayscale release test transaction related to the grayscale release stage; if the operating environment tag carried by the smart contract call transaction is a generated environment tag, or the smart contract call transaction does not carry the operating environment tag, it is determined that the smart contract call transaction is not a test transaction related to the grayscale upgrade.
[0320] Optionally, the management smart contract maintains a traffic diversion strategy for the smart contract call transaction;
[0321] Among them, in the pre-release stage for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release stage, call the new version of the business smart contract to execute the smart contract call transaction; otherwise, call the old version of the business smart contract to execute the smart contract call transaction;
[0322] The grayscale upgrading unit 930 includes:
[0323] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0324] Optionally, in the phase of grayscale release for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release phase; or a grayscale release test transaction related to the grayscale release phase, calling the new version of the business smart contract to execute the smart contract call transaction; otherwise, calling the old version of the business smart contract to execute the smart contract call transaction;
[0325] The grayscale upgrading unit 930 includes:
[0326] If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage; or, a grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
[0327] Optionally, the device further comprises:
[0328] A first strategy switching unit receives an upgrade request for the business smart contract initiated by a call initiator when the business smart contract passes a pre-release test corresponding to the pre-release stage; wherein the upgrade request includes a call parameter for indicating that the traffic diversion strategy maintained by the management smart contract is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the gray release stage; in response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameter, the traffic diversion strategy is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the gray release stage.
[0329] Optionally, the device further comprises:
[0330] The second strategy switching unit receives an upgrade request for the business smart contract initiated by the call initiator when the business smart contract passes the grayscale release test corresponding to the grayscale release stage; wherein the upgrade request includes a call parameter for indicating that the drainage strategy maintained by the management smart contract is switched from the drainage strategy of the grayscale release stage to the drainage strategy after the grayscale upgrade is completed; in response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameter, the drainage strategy is switched from the drainage strategy of the grayscale release stage to the drainage strategy after the grayscale upgrade is completed, so as to complete the grayscale upgrade for the business smart contract; wherein the drainage strategy after the grayscale upgrade is completed includes: calling the new version of the business smart contract by default to execute the smart contract call transaction.
[0331] Optionally, the device further comprises:
[0332] The third strategy switching unit receives a rollback request for the business smart contract initiated by the call initiator when the business smart contract fails the pre-release test or the grayscale release test; wherein the rollback request includes a call parameter for indicating that the traffic diversion strategy maintained by the management smart contract is switched to a default traffic diversion strategy; in response to the rollback request, the strategy switching logic contained in the management smart contract is called, and the traffic diversion strategy is switched to a default traffic diversion strategy based on the call parameter; wherein the default traffic diversion strategy includes: calling the old version of the business smart contract by default to execute the smart contract call transaction.
[0333] See also Fig.10 , is a module diagram of a grayscale upgrade device of a blockchain service platform provided in an embodiment of this specification, and the device corresponds to Figure 4 In the illustrated embodiment, the transaction processing logic supported by at least some node devices in the blockchain managed by the blockchain service platform is replaced with a new version of the transaction processing logic after the grayscale upgrade; the device includes:
[0334] The transaction receiving unit 1010 receives a blockchain transaction initiated by a transaction initiator;
[0335] A label adding unit 1020, in response to the blockchain transaction, adds an operating environment label indicating a type of a software operating environment of the transaction initiator to the blockchain transaction;
[0336] The grayscale upgrade unit 1030 sends the blockchain transaction with the operating environment tag added to the blockchain, so that the blockchain responds to the blockchain transaction, determines whether the blockchain transaction is a test transaction related to the grayscale upgrade based on the operating environment tag, and when it is determined that the blockchain transaction is a test transaction related to the grayscale upgrade, forwards the test transaction to a node device that supports the new version of the transaction processing logic for transaction processing; otherwise, forwards the test transaction to a node device that supports the old version of the transaction processing logic for transaction processing.
[0337] Optionally, the grayscale upgrade for the blockchain service platform includes: a pre-release phase for the transaction execution logic of the new version; and a grayscale release phase after the pre-release phase is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release phase, and a grayscale release environment corresponding to the grayscale release phase;
[0338] The label adding unit 1020 includes:
[0339] Determine a subunit to determine the software operating environment of the transaction initiator;
[0340] A first adding subunit, if the determined software operating environment is a pre-release environment, adds a pre-release environment tag indicating that the software operating environment is a pre-release environment to the blockchain transaction initiated by the transaction initiator;
[0341] A second adding subunit, if the determined software operating environment is a grayscale release environment, adds a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the blockchain transaction initiated by the transaction initiator;
[0342] The third adding subunit adds a production environment tag indicating that the software operating environment is a production environment to the blockchain transaction initiated by the transaction initiator if the determined software operating environment is a production environment.
[0343] Optionally, the device further comprises:
[0344] The replacement unit switches the current software running environment to the pre-release environment in response to a notification message issued by the blockchain service platform to replace the transaction processing logic supported by at least part of the node devices in the blockchain with a new version of the transaction processing logic after the grayscale upgrade.
[0345] Optionally, if the software operating environment is a pre-release environment, the device further includes:
[0346] The environment switching unit switches the current software running environment from the pre-release environment to the grayscale environment in response to a notification message issued by the blockchain service platform that the new version of the transaction processing logic has passed the pre-release test.
[0347] Optionally, if the software operating environment is a grayscale environment, the device further includes:
[0348] The environment switching unit switches the current software running environment from the grayscale release environment to the production environment in response to a notification message issued by the blockchain service platform that the new version of the transaction processing logic has passed the grayscale release test.
[0349] See also Fig.11 , is a module diagram of a grayscale upgrade device of a blockchain service platform provided in an embodiment of this specification, and the device corresponds to Figure 5 In the illustrated embodiment, the transaction processing logic supported by at least some node devices in the blockchain managed by the blockchain service platform is replaced with a new version of the transaction processing logic after the grayscale upgrade; the device includes:
[0350] The receiving unit 1110 receives a blockchain transaction initiated by a transaction initiator; wherein the blockchain transaction includes an operating environment tag indicating a type of a software operating environment of the transaction initiator;
[0351] A determining unit 1120, in response to the blockchain transaction, determines whether the blockchain transaction is a test transaction related to the grayscale upgrade based on the operating environment tag;
[0352] Processing unit 1130, if it is determined that the blockchain transaction is a test transaction related to the grayscale upgrade, forwards the test transaction to a node device that supports the new version of the transaction processing logic for transaction processing; otherwise, forwards the test transaction to a node device that supports the old version of the transaction processing logic for transaction processing.
[0353] Optionally, the grayscale upgrade for the blockchain service platform includes: a pre-release phase for the transaction execution logic of the new version; and a grayscale release phase after the pre-release phase is completed; the software operating environment includes a production environment, a pre-release environment corresponding to the pre-release phase, and a grayscale release environment corresponding to the grayscale release phase;
[0354] The determining unit 1120 includes:
[0355] A determination subunit determines the type of the operating environment tag carried by the blockchain transaction; if the operating environment tag carried by the blockchain transaction is a pre-release environment tag, the blockchain transaction is determined to be a pre-release test transaction related to the pre-release stage; if the operating environment tag carried by the blockchain transaction is a grayscale environment tag, the blockchain transaction is determined to be a grayscale release test transaction related to the grayscale release stage; if the operating environment tag carried by the blockchain transaction is a generated environment tag, or the blockchain transaction does not carry the operating environment tag, it is determined that the blockchain transaction is not a test transaction related to the grayscale upgrade.
[0356] Optionally, the blockchain service platform maintains a traffic diversion strategy for diverting traffic to the blockchain transaction;
[0357] Among them, in the pre-release stage for the transaction processing logic of the new version, the traffic diversion strategy includes: if the blockchain transaction is a pre-release test transaction related to the pre-release stage, forwarding the test transaction to a node device supporting the transaction processing logic of the new version for transaction processing; otherwise, forwarding the test transaction to a node device supporting the transaction processing logic of the old version for transaction processing;
[0358] The processing unit 1130 includes:
[0359] If it is determined that the blockchain transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the node device supporting the new version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the new version of the transaction processing logic for transaction processing; otherwise, the node device supporting the old version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the old version of the transaction processing logic for transaction processing.
[0360] Optionally, in the phase of grayscale release of the transaction processing logic of the new version, the traffic diversion strategy includes: if the blockchain transaction is a pre-release test transaction related to the pre-release phase; or a grayscale release test transaction related to the grayscale release phase, forwarding the test transaction to a node device supporting the new version of the transaction processing logic for transaction processing; otherwise, forwarding the test transaction to a node device supporting the old version of the transaction processing logic for transaction processing;
[0361] The processing unit 1130 includes:
[0362] If it is determined that the blockchain transaction is a pre-release test transaction related to the pre-release stage; or, a grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, the node device supporting the new version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the new version of the transaction processing logic for transaction processing; otherwise, the node device supporting the old version of the transaction processing logic is determined as the node device for executing the blockchain transaction, and the blockchain transaction is forwarded to the node device supporting the old version of the transaction processing logic for transaction processing.
[0363] Optionally, the device further comprises:
[0364] The grayscale upgrade subunit, based on a preset grayscale upgrade progress, sequentially increases the grayscale upgrade range of the node devices in the blockchain, and sequentially replaces the binary codes corresponding to the transaction processing logic supported by the node devices within the grayscale upgrade range with the binary codes corresponding to the new version of the transaction processing logic.
[0365] Optionally, the device further comprises:
[0366] An acquisition subunit, which acquires the execution result of the blockchain transaction from the node device;
[0367] a feedback sub-unit, which determines, based on the execution result, whether the transaction processing logic of the new version has passed a pre-release test corresponding to the pre-release stage; if so, sends a notification message to the transaction initiator that the transaction processing logic of the new version has passed the pre-release test; and, based on the execution result, determines whether the transaction processing logic of the new version has passed a grayscale release test corresponding to the grayscale release stage; if so, sends a notification message to the transaction initiator that the transaction processing logic of the new version has passed the grayscale release test.
[0368] Optionally, the device further comprises:
[0369] a first strategy switching unit, in response to the new version of the transaction processing logic passing the pre-release test, switching the traffic diversion strategy from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the phased release stage;
[0370] The second strategy switching unit, in response to the new version of the transaction processing logic passing the grayscale release test, switches the traffic diversion strategy from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed; wherein the traffic diversion strategy after the grayscale upgrade is completed includes: by default forwarding the blockchain transaction to a node device that supports the new version of the transaction processing logic for transaction processing.
[0371] Optionally, the device further comprises:
[0372] The third strategy switching unit switches the traffic diversion strategy to a default traffic diversion strategy in response to the new version of the transaction execution logic failing the pre-release test or the grayscale release test; wherein the default traffic diversion strategy includes: forwarding the blockchain transaction to a node device that supports the old version of the transaction processing logic for transaction processing by default.
[0373] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0374] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0375] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Ordinary technicians in this field can understand and implement it without paying creative work.
[0376] In the above-mentioned embodiment of the electronic device, it should be understood that the processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can be any conventional processor, etc., and the aforementioned memory can be a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk, or a solid-state drive. The steps of the method disclosed in the embodiments of this specification can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0377] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the electronic device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0378] Those skilled in the art will readily appreciate other embodiments of the present specification after considering the specification and practicing the embodiments disclosed herein. The present specification is intended to cover any variations, uses, or adaptations of the present specification that follow the general principles of the present specification and include common knowledge or customary techniques in the art that are not disclosed in the present specification. The description and embodiments are to be considered exemplary only, and the true scope and spirit of the present specification are indicated by the appended claims.
[0379] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.
Claims
1. A method for grayscale upgrading of smart contracts in a blockchain, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of the business smart contract after the grayscale upgrade; And, a management smart contract for grayscale upgrade management of the business smart contract; the method includes: Receiving a smart contract call transaction initiated by a call initiator for the business smart contract; In response to the smart contract call transaction, adding an operating environment tag indicating the type of the software operating environment of the call initiator to the smart contract call transaction; the grayscale upgrade includes a pre-release stage for the new version of the business smart contract, and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage; The smart contract call transaction with the operating environment label added is sent to the node device in the blockchain, so that the node device responds to the smart contract call transaction and calls the management smart contract deployed on the blockchain. If the operating environment label indicates that the software operating environment is a pre-release environment or a grayscale release environment, the smart contract call transaction is determined to be a test transaction related to the grayscale upgrade, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
2. According to the method of claim 1, the software operating environment also includes a production environment; The step of adding an operating environment tag indicating the type of the software operating environment of the call initiator to the smart contract call transaction includes: Determining the software operating environment of the call initiator; If the determined software operating environment is a pre-release environment, adding a pre-release environment tag indicating that the software operating environment is a pre-release environment to the smart contract call transaction initiated by the call initiator; If the determined software operating environment is a grayscale release environment, adding a grayscale environment tag indicating that the software operating environment is a grayscale release environment to the smart contract call transaction initiated by the call initiator; If the determined software operating environment is a production environment, a production environment tag indicating that the software operating environment is a production environment is added to the smart contract call transaction initiated by the call initiator.
3. The method according to claim 2, before receiving the smart contract call transaction initiated by the call initiator for the business smart contract, further comprises: Obtain the contract code of the new version of the business smart contract; Construct a smart contract creation transaction containing the contract code, and send the smart contract creation transaction to the node device in the blockchain, so that the node device executes the smart contract creation, creates the new version of the business smart contract in the blockchain based on the contract code, and completes the deployment of the new version of the business smart contract.
4. The method according to claim 3, further comprising: In response to the new version of the business smart contract being deployed on the blockchain, the current software operating environment is switched to the pre-release environment.
5. The method according to claim 4, if the software operating environment is a pre-release environment, the method further comprises: Obtaining the execution result of the smart contract call transaction from the node device; Determine, based on the execution result, whether the new version of the business smart contract passes the pre-release test corresponding to the pre-release stage; If so, the current software running environment is switched from the pre-release environment to the grayscale release environment.
6. The method according to claim 5, if the software operating environment is a grayscale release environment, the method further comprises: Obtaining the execution result of the smart contract call transaction from the node device; Determine, based on the execution result, whether the new version of the business smart contract passes the grayscale release test corresponding to the grayscale release stage; If so, the current software running environment is switched from the grayscale release environment to the production environment.
7. A method for grayscale upgrade of smart contracts in a blockchain, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of the business smart contract after the grayscale upgrade; and a management smart contract for grayscale upgrade management of the business smart contract; the method comprises: Receive a smart contract call transaction initiated by a call initiator for the business smart contract; wherein the smart contract call transaction includes an operating environment tag indicating the type of the software operating environment of the call initiator; the grayscale upgrade includes a pre-release stage for the new version of the business smart contract, and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage; In response to the smart contract call transaction, calling a management smart contract deployed on the blockchain; If the operating environment label indicates that the software operating environment is a pre-release environment or a grayscale release environment, the smart contract call transaction is determined to be a test transaction related to the grayscale upgrade, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
8. The method according to claim 7, wherein the software operating environment further comprises a production environment; If the operating environment tag indicates that the software operating environment is a pre-release environment or a grayscale release environment, determining that the smart contract call transaction is a test transaction related to the grayscale upgrade includes: Determine the type of the operating environment tag carried by the smart contract call transaction; If the operating environment tag carried by the smart contract call transaction is a pre-release environment tag, determining that the smart contract call transaction is a pre-release test transaction related to the pre-release stage; If the running environment tag carried by the smart contract call transaction is a grayscale environment tag, determining that the smart contract call transaction is a grayscale release test transaction related to the grayscale release stage; If the operating environment tag carried by the smart contract call transaction is a generated environment tag, or the smart contract call transaction does not carry the operating environment tag, it is determined that the smart contract call transaction is not a test transaction related to the grayscale upgrade.
9. According to the method of claim 7, the management smart contract maintains a traffic diversion strategy for the smart contract call transaction; in, In the pre-release stage for the business smart contract, the traffic diversion strategy includes: if the smart contract call transaction is a pre-release test transaction related to the pre-release stage, calling the new version of the business smart contract to execute the smart contract call transaction; otherwise, calling the old version of the business smart contract to execute the smart contract call transaction; If it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further cross-contract call the new version of the business smart contract to execute the smart contract call transaction; otherwise, further cross-contract call the old version of the business smart contract to execute the smart contract call transaction, including: If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage, based on the traffic diversion strategy of the pre-release stage, the new version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is determined as the business smart contract used to execute the smart contract call transaction, and the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
10. According to the method of claim 9, in the phase of grayscale release of the business smart contract, the traffic diversion strategy includes: If the smart contract call transaction is a pre-release test transaction related to the pre-release stage; Alternatively, a grayscale release test transaction related to the grayscale release stage calls the new version of the business smart contract to execute the smart contract call transaction; Otherwise, the old version of the business smart contract is called to execute the smart contract call transaction; If it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, further cross-contract call the new version of the business smart contract to execute the smart contract call transaction; On the contrary, further cross-contract calling the old version of the business smart contract to execute the smart contract call transaction includes: If it is determined that the smart contract call transaction is a pre-release test transaction related to the pre-release stage; Alternatively, the grayscale release test transaction related to the grayscale release stage, based on the traffic diversion strategy of the pre-release stage, determines the new version of the business smart contract as the business smart contract used to execute the smart contract call transaction, and further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; conversely, determines the old version of the business smart contract as the business smart contract used to execute the smart contract call transaction, and further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
11. The method according to claim 9, further comprising: Receiving an upgrade request for the business smart contract initiated by a call initiator when the business smart contract passes a pre-release test corresponding to the pre-release stage; wherein the upgrade request includes a call parameter for instructing the traffic diversion strategy maintained by the management smart contract to be switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the grayscale release stage; In response to the upgrade request, the strategy switching logic contained in the management smart contract is called, and based on the call parameters, the traffic diversion strategy is switched from the traffic diversion strategy of the pre-release stage to the traffic diversion strategy of the grayscale release stage.
12. The method according to claim 9, further comprising: Receive an upgrade request for the business smart contract initiated by a call initiator when the business smart contract passes the grayscale release test corresponding to the grayscale release stage; wherein the upgrade request includes a call parameter for instructing the traffic diversion strategy maintained by the management smart contract to be switched from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed; In response to the upgrade request, the strategy switching logic included in the management smart contract is called, and based on the call parameters, the traffic diversion strategy is switched from the traffic diversion strategy in the grayscale release stage to the traffic diversion strategy after the grayscale upgrade is completed, so as to complete the grayscale upgrade for the business smart contract; Among them, the traffic diversion strategy after the grayscale upgrade is completed includes: calling the new version of the business smart contract by default to execute the smart contract call transaction.
13. The method according to claim 9, further comprising: Receiving a rollback request for the business smart contract initiated by a call initiator when the business smart contract fails the pre-release test or the grayscale release test; wherein the rollback request includes a call parameter for instructing to switch the traffic diversion strategy maintained by the management smart contract to a default traffic diversion strategy; In response to the rollback request, calling the strategy switching logic included in the management smart contract, and switching the traffic diversion strategy to a default traffic diversion strategy based on the calling parameters; Among them, the default traffic diversion strategy includes: calling the old version of the business smart contract by default to execute the smart contract call transaction.
14. A grayscale upgrade device for smart contracts in a blockchain, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of a business smart contract after the grayscale upgrade; And, a management smart contract for grayscale upgrade management of the business smart contract; the device includes: A transaction receiving unit, receiving a smart contract call transaction initiated by a call initiator for the business smart contract; a label adding unit, in response to the smart contract call transaction, adding an operating environment label indicating the type of the software operating environment of the call initiator to the smart contract call transaction; the grayscale upgrade includes a pre-release stage for the new version of the business smart contract, and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage; The grayscale upgrade unit sends the smart contract call transaction with the operating environment label added to the node device in the blockchain, so that the node device responds to the smart contract call transaction and calls the management smart contract deployed on the blockchain. If the operating environment label indicates that the software operating environment is a pre-release environment or a grayscale release environment, when it is determined that the smart contract call transaction is a test transaction related to the grayscale upgrade, the new version of the business smart contract is further called across contracts to execute the smart contract call transaction; otherwise, the old version of the business smart contract is further called across contracts to execute the smart contract call transaction.
15. A grayscale upgrade device for smart contracts in a blockchain, wherein the blockchain deploys an old version of a business smart contract before the grayscale upgrade and a new version of a business smart contract after the grayscale upgrade; And, a management smart contract for grayscale upgrade management of the business smart contract; the device includes: A transaction receiving unit, receiving a smart contract call transaction initiated by a call initiator for the business smart contract; wherein the smart contract call transaction includes an operating environment tag indicating the type of the software operating environment of the call initiator; the grayscale upgrade includes a pre-release stage for the new version of the business smart contract, and a grayscale release stage after the pre-release stage is completed; the software operating environment includes a pre-release environment corresponding to the pre-release stage, and a grayscale release environment corresponding to the grayscale release stage; A contract calling unit, in response to the smart contract calling transaction, calling the management smart contract deployed on the blockchain; The grayscale upgrade unit determines that the smart contract call transaction is a test transaction related to the grayscale upgrade if the operating environment label indicates that the software operating environment is a pre-release environment or a grayscale release environment, and further calls the new version of the business smart contract across contracts to execute the smart contract call transaction; otherwise, further calls the old version of the business smart contract across contracts to execute the smart contract call transaction.
16. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 13 by running the executable instructions.
Citation Information
Patent Citations
Gray scale upgrading method and device of block chain service platform, and electronic equipment
CN114816493A