CN111522829A - Method for realizing distributed lock on block chain - Google Patents

Method for realizing distributed lock on block chain Download PDF

Info

Publication number
CN111522829A
CN111522829A CN202010329756.6A CN202010329756A CN111522829A CN 111522829 A CN111522829 A CN 111522829A CN 202010329756 A CN202010329756 A CN 202010329756A CN 111522829 A CN111522829 A CN 111522829A
Authority
CN
China
Prior art keywords
lock
locking
application server
interface
blockchain
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010329756.6A
Other languages
Chinese (zh)
Other versions
CN111522829B (en
Inventor
李伟浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Qidi Network Technology Co ltd
Original Assignee
Shenzhen Qidi Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Qidi Network Technology Co ltd filed Critical Shenzhen Qidi Network Technology Co ltd
Priority to CN202010329756.6A priority Critical patent/CN111522829B/en
Publication of CN111522829A publication Critical patent/CN111522829A/en
Application granted granted Critical
Publication of CN111522829B publication Critical patent/CN111522829B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural

Abstract

The invention discloses a method for realizing distributed locks on a block chain, which is characterized in that each application server is preset with a unique block chain key pair, an authorization distribution center deploys an intelligent contract on the block chain, a contract interface is called to set an authorized application server list for each type of lock, and the application server calls the contract interface to realize locking and unlocking.

Description

Method for realizing distributed lock on block chain
Technical Field
The invention relates to the technical field of distributed locks, in particular to a method for realizing distributed locks on a block chain.
Background
In the case of multi-system interaction, sometimes it is necessary to coordinate the associated operations among the systems so that the operations of the systems can be executed synchronously or mutually exclusively.
Distributed locks are one way to control the synchronous access to shared resources between distributed systems. In distributed systems, it is often necessary to coordinate their actions. If one or a group of resources are shared between different systems or different hosts of the same system, then access to these resources often requires mutual exclusion to prevent interference with each other to ensure consistency, in which case a distributed lock is used.
At present, only centralized distributed lock implementation methods such as a cache-based redis/memcached distributed lock, a database-based mysql/mssql record lock distributed lock, a zookeeper-based distributed lock, and the like are available, and no decentralized distributed lock implementation method is found.
Disclosure of Invention
The present invention provides a method for implementing distributed locks on a block chain, so as to solve the problems in the background art.
In order to achieve the purpose, the invention provides the following technical scheme:
a distributed lock implementation method on a block chain comprises an authorized distribution center, a plurality of application servers and an intelligent contract on the block chain, wherein each application server sets a unique block chain key pair in advance, the authorized distribution center deploys the intelligent contract on the block chain, a contract interface is called to set an authorized application server list for each type of lock, and the application server calls the contract interface to implement locking and unlocking.
As a further scheme of the present invention, the authorization distribution center may deploy an intelligent contract on the blockchain, invoke an intelligent contract interface, and maintain a list of application servers authorized by each type of lock.
As a further scheme of the present invention, a unique blockchain key pair is set in the application server, and a locking or unlocking interface of an intelligent contract on a blockchain can be called to implement locking and unlocking.
As a further scheme of the present invention, a plurality of locks classified by name are stored in the intelligent contract on the block chain, a plurality of locks identified by lock IDs may be stored in the classification, and call interfaces for maintaining lock classification, locking, unlocking, and the like are provided externally.
As a further scheme of the present invention, a specific implementation method is as follows:
s001: an intelligent contract C is deployed on a blockchain by an authorization distribution center, each application server is set as T, the application server maintains a unique key pair of the application server, and blockchain addresses corresponding to the key pair are set as T1 and T2;
s002: the authorization distribution center calls an authorization interface on the C for a certain type of lock L, the authorization interface comprises an application server address list authorized by the parameter L, and each time the authorization setting which covers the same name of the original L is called;
s003: assertion: if there is a record and the blockchain address of T is in the list, then S004 is executed, otherwise S006 is executed;
s004: c, searching a locking table according to the lock type L and the lock ID, and finding out a corresponding record R, wherein the C stores a lock type authorization table, and the record types are as follows: lock class name L, list of authorized blockchain addresses; the application server has a locking table, and the record type is as follows: the identification ID of the lock L, the lock holder address and the lock timeout time;
s005: assertion: if R does not exist, or the holder T of R exists, or the lock timeout time of R is earlier than the current time on the chain, executing S006, otherwise executing S007;
s006: the operation fails and the output ends.
S007: if R exists, deleting the R, adding records to the locking table, wherein the record content comprises ID, T address and current time on the chain;
s008: if the locking is successful, the application server executes the corresponding service logic after the locking, when the application server locks, the unique key pair of the application server is used for signing and calling the locking interface on the C, the locking interface comprises the identification ID of the lock L and the maximum locking seconds, and if the locking is successful, the locking is successful;
s009: the signature of T calls an unlocking interface on C, C searches a locking table according to the lock type L and the lock ID to find out a corresponding record R, when the application server unlocks, the signature of the unique key pair of the application server calls the unlocking interface on C, and the unlocking interface comprises the identification ID of the lock L;
s010: assertion: if R exists and the owner on R is T and the locking timeout time is later than the current time on the chain, executing S011, otherwise executing S012;
s011: deleting R, and finishing unlocking;
s012: the operation is successful and the output is finished.
Compared with the prior art, the invention has the beneficial effects that:
the invention uses the characteristics of decentralized block chain and no double flowers on the digital assets, and uses the operation of transferring all balance out through the fixed account number as locking.
Drawings
Fig. 1 is a flowchart of locking and unlocking an application server T in a method for implementing a distributed lock on a blockchain.
Fig. 2 is an implementation block diagram of a distributed lock implementation method on a blockchain.
In the figure: 1. an authorized distribution center; 2. intelligent contracts on block chains; 3. an application server.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1-2, in an embodiment of the present invention, a method for implementing a distributed lock on a block chain includes an authorized distribution center 1, a plurality of application servers 3, and an intelligent contract 2 on a block chain;
the authorization distribution center 1 can deploy the intelligent contract 2 on the block chain, call an intelligent contract interface and maintain a list of the application servers 3 authorized by each type of lock;
a unique block chain key pair is set in the application server 3, and a locking or unlocking interface of the intelligent contract 2 on the block chain can be called to realize locking and unlocking;
a plurality of locks classified according to names are stored in the intelligent contract 2 on the block chain, a plurality of locks identified according to lock IDs can be arranged in the classification, and call interfaces for maintaining lock classification, locking, unlocking and the like are externally provided;
the method comprises the steps that a unique block chain key pair is set in each application server 3 in advance, an intelligent contract is deployed on a block chain by the authorization distribution center 1, a contract interface is called to set an authorized application server list for each type of lock, and the application server 3 calls the contract interface to lock and unlock.
The specific implementation method comprises the following steps:
s001: an intelligent contract C is deployed on a blockchain by the authorization distribution center 1, each application server 3 is set to be T, the application server 3 maintains a unique key pair of the application server 3, and blockchain addresses corresponding to the key pairs are set to be T1 and T2 respectively;
s002: the authorization distribution center 1 calls an authorization interface on the C for a certain type of lock L, the authorization interface comprises an application server address list authorized by the parameter L, and each time the authorization setting with the same name of the original L is covered;
s003: assertion: if there is a record and the blockchain address of T is in the list, then S004 is executed, otherwise S006 is executed;
s004: c, searching a locking table according to the lock type L and the lock ID, and finding out a corresponding record R, wherein the C stores a lock type authorization table, and the record types are as follows: lock class name L, list of authorized blockchain addresses; the application server 3 has a locking table, and the record types are: the identification ID of the lock L, the lock holder address and the lock timeout time;
s005: assertion: if R does not exist, or the holder T of R exists, or the lock timeout time of R is earlier than the current time on the chain, executing S006, otherwise executing S007;
s006: the operation fails and the output ends.
S007: if R exists, deleting the R, adding records to the locking table, wherein the record content comprises ID, T address and current time on the chain;
s008: if the locking is successful, the application server 3 executes the corresponding service logic after the locking, when the application server 3 locks, the unique key pair of the application server is used for signing and calling the locking interface on the C, the locking interface comprises the identification ID of the lock L and the maximum locking seconds, and if the locking is successful, the locking is successful;
s009: the signature of T calls an unlocking interface on C, C searches a locking table according to the lock type L and the lock ID to find out a corresponding record R, when the application server 3 unlocks, the signature of the unique key pair of the application server 3 calls the unlocking interface on C, and the unlocking interface comprises the identification ID of the lock L;
s010: assertion: if R exists and the owner on R is T and the locking timeout time is later than the current time on the chain, executing S011, otherwise executing S012;
s011: deleting R, and finishing unlocking;
s012: the operation is successful and the output is finished.
The invention uses the characteristics of decentralized block chain and no double flowers on the digital assets, and uses the operation of transferring all balance out through the fixed account number as locking.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art should be considered to be within the technical scope of the present invention, and the technical solutions and the inventive concepts thereof according to the present invention should be equivalent or changed within the scope of the present invention.

Claims (5)

1. A distributed lock implementation method on a block chain comprises an authorized distribution center (1), a plurality of application servers (3) and an intelligent contract (2) on the block chain, and is characterized in that each application server (3) is preset with a unique block chain key pair, the authorized distribution center (1) deploys the intelligent contract on the block chain, a contract interface is called to set an authorized application server list for each type of lock, and the application servers (3) call the contract interface to implement locking and unlocking.
2. A distributed lock implementation method on blockchain according to claim 1, wherein the authorization distribution center (1) can deploy intelligent contracts (2) on blockchain, invoke intelligent contract interfaces, and maintain a list of application servers (3) authorized by each type of lock.
3. The method for implementing distributed lock on blockchain according to claim 1, wherein a unique blockchain key pair is set in the application server (3), and a locking or unlocking interface of the smart contract (2) on blockchain can be invoked to implement locking and unlocking.
4. The method for implementing distributed locks on blockchains according to claim 1, wherein a plurality of locks classified by name are stored in the intelligent contract (2) on blockchains, a plurality of locks identified by lock IDs can be stored in the classification, and a call interface for maintaining lock classification, locking and unlocking is provided externally.
5. The method for implementing distributed locks on blockchains according to any one of claims 1 to 4, comprising the following steps:
s001: an intelligent contract C is deployed on a blockchain by an authorization distribution center (1), each application server (3) is set to be T, the application servers (3) maintain unique key pairs of the application servers, and blockchain addresses corresponding to the key pairs are set to be T1 and T2;
s002: the authorization distribution center (1) calls an authorization interface on the C for a certain type of lock L, the authorization interface comprises an application server address list authorized by the parameter L, and each time the authorization setting of the same name of the original L is covered;
s003: assertion: if there is a record and the blockchain address of T is in the list, then S004 is executed, otherwise S006 is executed;
s004: c, searching a locking table according to the lock type L and the lock ID, and finding out a corresponding record R, wherein the C stores a lock type authorization table, and the record types are as follows: lock class name L, list of authorized blockchain addresses; the application server (3) is provided with a locking table, and the record types are as follows: the identification ID of the lock L, the lock holder address and the lock timeout time;
s005: assertion: if R does not exist, or the holder T of R exists, or the lock timeout time of R is earlier than the current time on the chain, executing S006, otherwise executing S007;
s006: the operation is failed, and the output is finished;
s007: if R exists, deleting the R, adding records to the locking table, wherein the record content comprises ID, T address and current time on the chain;
s008: if the locking is successful, the application server (3) executes the corresponding service logic after the locking, when the application server (3) locks, the unique key pair of the application server is used for signing and calling the locking interface on the C, wherein the locking interface comprises the identification ID of the lock L and the maximum locking seconds, and if the locking is successful, the locking is successful;
s009: the signature calls an unlocking interface on the C, the C searches a locking table according to the lock type L and the lock ID to find out a corresponding record R, when the application server (3) is unlocked, the signature calls the unlocking interface on the C by using a unique key pair of the application server, and the unlocking interface comprises the identification ID of the lock L;
s010: assertion: if R exists and the owner on R is T and the locking timeout time is later than the current time on the chain, executing S011, otherwise executing S012;
s011: deleting R, and finishing unlocking;
s012: the operation is successful and the output is finished.
CN202010329756.6A 2020-04-14 2020-04-14 Method for realizing distributed lock on block chain Active CN111522829B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010329756.6A CN111522829B (en) 2020-04-14 2020-04-14 Method for realizing distributed lock on block chain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010329756.6A CN111522829B (en) 2020-04-14 2020-04-14 Method for realizing distributed lock on block chain

Publications (2)

Publication Number Publication Date
CN111522829A true CN111522829A (en) 2020-08-11
CN111522829B CN111522829B (en) 2023-11-28

Family

ID=71904691

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010329756.6A Active CN111522829B (en) 2020-04-14 2020-04-14 Method for realizing distributed lock on block chain

Country Status (1)

Country Link
CN (1) CN111522829B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013000135A1 (en) * 2011-06-29 2013-01-03 中兴通讯股份有限公司 Locking method and system for distributed messages
US9992022B1 (en) * 2017-02-06 2018-06-05 Northern Trust Corporation Systems and methods for digital identity management and permission controls within distributed network nodes
CN108564692A (en) * 2018-04-10 2018-09-21 周伟 A kind of unlock verification method and system for unlocking based on block chain
CN109685489A (en) * 2018-12-28 2019-04-26 杭州云象网络技术有限公司 A kind of assets across chain method of commerce between block chain
CN109828847A (en) * 2019-01-25 2019-05-31 平安科技(深圳)有限公司 Lock processing method, device, computer equipment and storage medium based on block chain
CN110188572A (en) * 2019-05-22 2019-08-30 深圳前海微众银行股份有限公司 A kind of verification method and device for consuming voucher applied to block chain
CA3005560A1 (en) * 2018-05-22 2019-11-22 Damir Olejar Method and system for smart-contract controlled and event-driven financial planning on a blockchain

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013000135A1 (en) * 2011-06-29 2013-01-03 中兴通讯股份有限公司 Locking method and system for distributed messages
US9992022B1 (en) * 2017-02-06 2018-06-05 Northern Trust Corporation Systems and methods for digital identity management and permission controls within distributed network nodes
CN108564692A (en) * 2018-04-10 2018-09-21 周伟 A kind of unlock verification method and system for unlocking based on block chain
CA3005560A1 (en) * 2018-05-22 2019-11-22 Damir Olejar Method and system for smart-contract controlled and event-driven financial planning on a blockchain
CN109685489A (en) * 2018-12-28 2019-04-26 杭州云象网络技术有限公司 A kind of assets across chain method of commerce between block chain
CN109828847A (en) * 2019-01-25 2019-05-31 平安科技(深圳)有限公司 Lock processing method, device, computer equipment and storage medium based on block chain
CN110188572A (en) * 2019-05-22 2019-08-30 深圳前海微众银行股份有限公司 A kind of verification method and device for consuming voucher applied to block chain

Also Published As

Publication number Publication date
CN111522829B (en) 2023-11-28

Similar Documents

Publication Publication Date Title
CN109828847B (en) Block chain-based lock processing method, device, computer equipment and storage medium
US10310913B2 (en) Method, device and system for processing parallel services
WO2020248768A1 (en) Method and apparatus for managing application program service
CN109558218A (en) A kind of distributed service data lock implementation method based on Redis
EP2534587B1 (en) Data management at a directory database
US10972901B2 (en) Remote SIM unlock (RSU) implementation using blockchain
CN109191649B (en) Method and device for sharing control authority of intelligent door lock
CN105138310A (en) Concurrent access control method and system
CN108280150A (en) A kind of distribution asynchronous service distribution method and system
CN116455951B (en) Calling method for realizing RPC isolation of multi-tenant service based on dynamic rules
CN111522829A (en) Method for realizing distributed lock on block chain
CN102243653A (en) Method and device for managing database connections
CN102243655A (en) Method and device for managing database connections
US9794351B2 (en) Distributed management with embedded agents in enterprise apps
CN108733477B (en) Method, device and equipment for data clustering processing
CN112667409A (en) Implementation method of reentrant distributed exclusive lock
CN113067861A (en) Distributed extensible access control authorization system and method based on block chain
CN110445765A (en) Data sharing method, terminal device and medium based on block chain
CN113612732B (en) Resource calling method and device and multiparty secure computing system
CN111428226B (en) Method for safely calling password card interface
CN108259545B (en) Port security policy diffusion method and device
CN114327938A (en) PISA manager implementation mode under Linux system
CN106131354A (en) Dialing method for building up and system
CN116089044A (en) Timing task scheduling method, device, equipment and storage medium
CN109493855A (en) Speech-sound intelligent locks method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant