Skip to content

Commit

Permalink
feat(ref-imp): #890 - ability to turn of value time lock updates
Browse files Browse the repository at this point in the history
* feat(ref-imp): #890 - ability to turn of value time lock updates using a dedicated parameter
* refactor(ref-imp): removed currentLockState in LockMonitor
* fix(ref-imp): various minor fixes and logging improvements
  • Loading branch information
thehenrytsai authored Oct 16, 2020
1 parent 13e0563 commit 6ea1ea4
Show file tree
Hide file tree
Showing 25 changed files with 212 additions and 438 deletions.
63 changes: 0 additions & 63 deletions docker-compose.yml

This file was deleted.

31 changes: 31 additions & 0 deletions docs/bitcoin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Bitcoin Blockchain Service Reference Implementation


## Value Time Lock

### Protocol parameters

| Protocol parameters | Description |
| ------------------------------------ | ---------------------------------------- |
| minimumValueTimeLockDurationInBlocks | TODO |
| maximumValueTimeLockDurationInBlocks | TODO |

### Configuration parameters
* valueTimeLockUpdateEnabled

This parameter controls whether the value time lock is actively being renewed and if the funds will be returned to wallet in case of `valueTimeLockAmountInBitcoins` being set to zero. When this parameter is set to `false`, parameters `valueTimeLockAmountInBitcoins`, `valueTimeLockPollPeriodInSeconds` and `valueTimeLockTransactionFeesAmountInBitcoins` will be ignored.

* valueTimeLockAmountInBitcoins

The desired fund locked to write larger operation batches. Set to 0 will causes existing locked fund (if exists) to be released back to wallet upon lock expiry.

* valueTimeLockPollPeriodInSeconds

The polling duration between checks to see if the value time lock needs to be re-locked or released back to wallet.

* valueTimeLockTransactionFeesAmountInBitcoins

The fund allocated for transaction fees for subsequent re-locking of the initial value time lock.

> Developer's note:
This allotted amount is locked together with value time lock for simplicity of re-lock implementation. If this allotted amount is depleted due to subsequent re-locks, the remaining locked amount will be released back to wallet, and a new lock will be created with this allotted amount added to it again.
142 changes: 3 additions & 139 deletions docs/implementation.md → docs/core.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sidetree Node.js Implementation Document
# Sidetree Core Node.js Implementation Document

This document focuses on the Node.js implementation of the Sidetree protocol.

Expand Down Expand Up @@ -82,6 +82,7 @@ The orchestration layer requires implementation of following interfaces per prot
- `IRequestHandler` - Handles REST API requests.


## Core Service REST API

### REST API HTTP Response status codes

Expand All @@ -94,9 +95,7 @@ The orchestration layer requires implementation of following interfaces per prot
| 500 | Server error. |



## Core Serivce REST API
The Core Service REST API impliments the [Sidetree REST API](https://identity.foundation/sidetree/api/), in addition it also exposes the following version API.
The Core Service REST API implements the [Sidetree REST API](https://identity.foundation/sidetree/api/), in addition it also exposes the following version API.

### Fetch the current service versions.
Fetches the current version of the core and the dependent services. The service implementation defines the versioning scheme and its interpretation.
Expand Down Expand Up @@ -698,141 +697,6 @@ HTTP/1.1 200 OK
}
```


## CAS REST API
The CAS (content addressable storage) REST API interface aims to abstract the underlying Sidetree storage away from the main protocol logic. This allows the CAS to be updated or even replaced if needed without affecting the core protocol logic. Conversely, the interface also allows the protocol logic to be implemented in an entirely different language while interfacing with the same CAS.

All hashes used in the API are encoded multihash as specified by the Sidetree protocol.

### Read content
Read the content of a given address and return it in the response body as octet-stream.

#### Request path
```
GET /<hash>?max-size=<maximum-allowed-size>
```

#### Request query parameters
- `max-size`

Required.

If the content exceeds the specified maximum allowed size, `HTTP 400 Bad Request` with `content_exceeds_maximum_allowed_size` as the value for the `code` parameter in a JSON body is returned.


#### Request example
```
GET /QmWd5PH6vyRH5kMdzZRPBnf952dbR4av3Bd7B2wBqMaAcf
```
#### Response headers
| Name | Value |
| --------------------- | ---------------------- |
| ```Content-Type``` | ```application/octet-stream``` |

#### Response example - Resoucre not found

```http
HTTP/1.1 404 Not Found
```

#### Response example - Content exceeds maximum allowed size

```http
HTTP/1.1 400 Bad Request
{
"code": "content_exceeds_maximum_allowed_size"
}
```

#### Response example - Content not a file

```http
HTTP/1.1 400 Bad Request
{
"code": "content_not_a_file"
}
```

#### Response example - Content hash is invalid

```http
HTTP/1.1 400 Bad Request
{
"code": "content_hash_invalid"
}
```

### Write content
Write content to CAS.

#### Request path
```
POST /
```

#### Request headers
| Name | Value |
| --------------------- | ---------------------- |
| ```Content-Type``` | ```application/octet-stream``` |

#### Response headers
| Name | Value |
| --------------------- | ---------------------- |
| ```Content-Type``` | ```application/json``` |

#### Response body schema
```json
{
"hash": "Hash of data written to CAS"
}
```

#### Response body example
```json
{
"hash": "QmWd5PH6vyRH5kMdzZRPBnf952dbR4av3Bd7B2wBqMaAcf"
}
```

### Fetch the current service version
Fetches the current version of the service. The service implementation defines the versioning scheme and its interpretation.

Returns the service _name_ and _version_ of the CAS service.

#### Request path
```
GET /version
```

#### Request headers
None.

#### Request example
```
GET /version
```

#### Response body schema
```json
{
"name": "A string representing the name of the service",
"version": "A string representing the version of currently running service."
}
```

#### Response example
```http
HTTP/1.1 200 OK
{
"name": "ipfs",
"version": "1.0.0"
}
```

## Frequently Asked Questions
### Why is the signature not verified before a request is queued and written to the blockchain?
End users are expected to use a "user agent" for making requests which should almost always generate the right signature,
Expand Down
33 changes: 0 additions & 33 deletions docs/docker.md

This file was deleted.

2 changes: 1 addition & 1 deletion lib/bitcoin/BitcoinBlockDataIterator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BitcoinFileReader from './BitcoinFileReader';
import BitcoinBlockModel from './models/BitcoinBlockModel';
import BitcoinFileReader from './BitcoinFileReader';
import BitcoinRawDataParser from './BitcoinRawDataParser';

/**
Expand Down
16 changes: 8 additions & 8 deletions lib/bitcoin/BitcoinClient.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as httpStatus from 'http-status';
import { Address, Block, Networks, PrivateKey, Script, Transaction, Unit, crypto } from 'bitcore-lib';
import nodeFetch, { FetchError, RequestInit, Response } from 'node-fetch';
import BitcoinBlockModel from './models/BitcoinBlockModel';
import BitcoinSidetreeTransactionModel from './models/BitcoinSidetreeTransactionModel';
import BitcoinInputModel from './models/BitcoinInputModel';
import BitcoinSidetreeTransactionModel from './models/BitcoinSidetreeTransactionModel';
import BitcoinLockTransactionModel from './models/BitcoinLockTransactionModel';
import BitcoinOutputModel from './models/BitcoinOutputModel';
import BitcoinTransactionModel from './models/BitcoinTransactionModel';
import BitcoinWallet from './BitcoinWallet';
import IBitcoinWallet from './interfaces/IBitcoinWallet';
import nodeFetch, { FetchError, RequestInit, Response } from 'node-fetch';
import ReadableStream from '../common/ReadableStream';
import { Address, Block, Networks, PrivateKey, Script, Transaction, Unit, crypto } from 'bitcore-lib';
import { IBlockInfo } from './BitcoinProcessor';
import ReadableStream from '../common/ReadableStream';

/**
* Structure (internal to this class) to store the transaction information
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class BitcoinClient {
* @param bitcoinLockTransaction The transaction object.
*/
public async broadcastLockTransaction (bitcoinLockTransaction: BitcoinLockTransactionModel): Promise<string> {
const transactionHash = this.broadcastTransactionRpc(bitcoinLockTransaction.serializedTransactionObject);
const transactionHash = await this.broadcastTransactionRpc(bitcoinLockTransaction.serializedTransactionObject);
console.info(`Broadcasted lock transaction: ${transactionHash}`);

return transactionHash;
Expand Down Expand Up @@ -590,8 +590,8 @@ export default class BitcoinClient {
previousFreezeDurationInBlocks: number,
newFreezeDurationInBlocks: number): Promise<[Transaction, Script]> {

// tslint:disable-next-line: max-line-length
console.info(`Creating a freeze transaction with freeze time in blocks: ${newFreezeDurationInBlocks} from previously frozen transaction with id: ${previousFreezeTransaction.id}`);
// eslint-disable-next-line max-len
console.info(`Creating a freeze transaction with freeze time of ${newFreezeDurationInBlocks} blocks, from previously frozen transaction with id: ${previousFreezeTransaction.id}`);

const freezeScript = BitcoinClient.createFreezeScript(newFreezeDurationInBlocks, this.bitcoinWallet.getAddress());
const payToScriptHashOutput = Script.buildScriptHashOut(freezeScript);
Expand All @@ -611,7 +611,7 @@ export default class BitcoinClient {
previousFreezeTransaction: BitcoreTransactionWrapper,
previousFreezeDurationInBlocks: number): Promise<Transaction> {

// tslint:disable-next-line: max-line-length
// eslint-disable-next-line max-len
console.info(`Creating a transaction to return (to the wallet) the previously frozen amount from transaction with id: ${previousFreezeTransaction.id} which was frozen for block duration: ${previousFreezeDurationInBlocks}`);

return this.createSpendTransactionFromFrozenTransaction(
Expand Down
2 changes: 1 addition & 1 deletion lib/bitcoin/BitcoinFileReader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import ErrorCode from './ErrorCode';
import IBitcoinFileReader from './interfaces/IBitcoinFileReader';
import SidetreeError from '../common/SidetreeError';
import * as fs from 'fs';

/**
* concrete implementation of BitcoinFileReader
Expand Down
Loading

0 comments on commit 6ea1ea4

Please sign in to comment.