mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-26 05:10:02 +00:00
Compare commits
4 Commits
v0.11.2
...
github-dep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7de07cdc97 | ||
|
|
921ca19b42 | ||
|
|
98c2dc8189 | ||
|
|
37654156a6 |
4
.github/workflows/SetPageFileSize.ps1
vendored
4
.github/workflows/SetPageFileSize.ps1
vendored
@@ -11,8 +11,8 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
param(
|
||||||
[System.UInt64] $MinimumSize = 16gb ,
|
[System.UInt64] $MinimumSize = 8gb ,
|
||||||
[System.UInt64] $MaximumSize = 16gb ,
|
[System.UInt64] $MaximumSize = 8gb ,
|
||||||
[System.String] $DiskRoot = "D:"
|
[System.String] $DiskRoot = "D:"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
76
.github/workflows/deploy.yaml
vendored
76
.github/workflows/deploy.yaml
vendored
@@ -1,76 +0,0 @@
|
|||||||
name: Build and upload assets
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [ published ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
|
||||||
name: Building, ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- name: Fix CRLF on Windows
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: git config --global core.autocrlf false
|
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# Increase the pagefile size on Windows to aviod running out of memory
|
|
||||||
- name: Increase pagefile size on Windows
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: powershell -command .github\workflows\SetPageFileSize.ps1
|
|
||||||
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
|
|
||||||
- name: Build on Linux
|
|
||||||
if: runner.os == 'Linux'
|
|
||||||
# `-extldflags=-static` - means static link everything,
|
|
||||||
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
|
|
||||||
# `-s -w` strips the binary to produce smaller size binaries
|
|
||||||
run: |
|
|
||||||
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ . ./cmd/...
|
|
||||||
archive="bin/kaspad-${{ github.event.release.tag_name }}-linux.zip"
|
|
||||||
asset_name="kaspad-${{ github.event.release.tag_name }}-linux.zip"
|
|
||||||
zip -r "${archive}" ./bin/*
|
|
||||||
echo "archive=${archive}" >> $GITHUB_ENV
|
|
||||||
echo "asset_name=${asset_name}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Build on Windows
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
go build -v -ldflags="-s -w" -o bin/ . ./cmd/...
|
|
||||||
archive="bin/kaspad-${{ github.event.release.tag_name }}-win64.zip"
|
|
||||||
asset_name="kaspad-${{ github.event.release.tag_name }}-win64.zip"
|
|
||||||
powershell "Compress-Archive bin/* \"${archive}\""
|
|
||||||
echo "archive=${archive}" >> $GITHUB_ENV
|
|
||||||
echo "asset_name=${asset_name}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Build on MacOS
|
|
||||||
if: runner.os == 'macOS'
|
|
||||||
run: |
|
|
||||||
go build -v -ldflags="-s -w" -o ./bin/ . ./cmd/...
|
|
||||||
archive="bin/kaspad-${{ github.event.release.tag_name }}-osx.zip"
|
|
||||||
asset_name="kaspad-${{ github.event.release.tag_name }}-osx.zip"
|
|
||||||
zip -r "${archive}" ./bin/*
|
|
||||||
echo "archive=${archive}" >> $GITHUB_ENV
|
|
||||||
echo "asset_name=${asset_name}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
|
|
||||||
- name: Upload release asset
|
|
||||||
uses: actions/upload-release-asset@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
upload_url: ${{ github.event.release.upload_url }}
|
|
||||||
asset_path: "./${{ env.archive }}"
|
|
||||||
asset_name: "${{ env.asset_name }}"
|
|
||||||
asset_content_type: application/zip
|
|
||||||
68
.github/workflows/go-deploy.yml
vendored
Normal file
68
.github/workflows/go-deploy.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
name: Build and Upload assets
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||||
|
name: Building For ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Fix windows CRLF
|
||||||
|
run: git config --global core.autocrlf false
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# We need to increase the page size because the tests run out of memory on github CI windows.
|
||||||
|
# Use the powershell script from this github action: https://github.com/al-cheb/configure-pagefile-action/blob/master/scripts/SetPageFileSize.ps1
|
||||||
|
# MIT License (MIT) Copyright (c) 2020 Maxim Lobanov and contributors
|
||||||
|
- name: Increase page size on windows
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: powershell
|
||||||
|
run: powershell -command .\.github\workflows\SetPageFileSize.ps1
|
||||||
|
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.16
|
||||||
|
|
||||||
|
- name: Build on linux
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
# `-extldflags=-static` - means static link everything, `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
|
||||||
|
# `-s -w` strips the binary to produce smaller size binaries
|
||||||
|
run: |
|
||||||
|
binary="kaspad-${{ github.event.release.tag_name }}-linux"
|
||||||
|
echo "binary=${binary}" >> $GITHUB_ENV
|
||||||
|
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o "${binary}"
|
||||||
|
|
||||||
|
- name: Build on Windows
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
binary="kaspad-${{ github.event.release.tag_name }}-win64.exe"
|
||||||
|
echo "binary=${binary}" >> $GITHUB_ENV
|
||||||
|
go build -v -ldflags="-s -w" -o "${binary}"
|
||||||
|
|
||||||
|
- name: Build on MacOS
|
||||||
|
if: runner.os == 'macOS'
|
||||||
|
run: |
|
||||||
|
binary="kaspad-${{ github.event.release.tag_name }}-osx"
|
||||||
|
echo "binary=${binary}" >> $GITHUB_ENV
|
||||||
|
go build -v -ldflags="-s -w" -o "${binary}"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Upload Release Asset
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ github.event.release.upload_url }}
|
||||||
|
asset_path: "./${{ env.binary }}"
|
||||||
|
asset_name: "${{ env.binary }}"
|
||||||
|
asset_content_type: application/zip
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Race
|
name: Go-Race
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
@@ -7,7 +7,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
race_test:
|
race_test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -19,10 +19,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup Go
|
- name: Set up Go 1.x
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.15
|
||||||
|
|
||||||
- name: Set scheduled branch name
|
- name: Set scheduled branch name
|
||||||
shell: bash
|
shell: bash
|
||||||
70
.github/workflows/go.yml
vendored
Normal file
70
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
# edtited - "title, body, or the base branch of the PR is modified"
|
||||||
|
# synchronize - "commit(s) pushed to the pull request"
|
||||||
|
types: [opened, synchronize, edited, reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-16.04, macos-10.15 ]
|
||||||
|
name: Testing on on ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Fix windows CRLF
|
||||||
|
run: git config --global core.autocrlf false
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# We need to increase the page size because the tests run out of memory on github CI windows.
|
||||||
|
# Use the powershell script from this github action: https://github.com/al-cheb/configure-pagefile-action/blob/master/scripts/SetPageFileSize.ps1
|
||||||
|
# MIT License (MIT) Copyright (c) 2020 Maxim Lobanov and contributors
|
||||||
|
- name: Increase page size on windows
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: powershell
|
||||||
|
run: powershell -command .\.github\workflows\SetPageFileSize.ps1
|
||||||
|
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.16
|
||||||
|
|
||||||
|
|
||||||
|
# Source: https://github.com/actions/cache/blob/main/examples.md#go---modules
|
||||||
|
- name: Go Cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
shell: bash
|
||||||
|
run: ./build_and_test.sh -v
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
name: Produce code coverage
|
||||||
|
steps:
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.16
|
||||||
|
|
||||||
|
- name: Create coverage file
|
||||||
|
run: go test -v -covermode=atomic -coverpkg=./... -coverprofile coverage.txt ./...
|
||||||
|
|
||||||
|
- name: Upload coverage file
|
||||||
|
run: bash <(curl -s https://codecov.io/bash)
|
||||||
98
.github/workflows/tests.yaml
vendored
98
.github/workflows/tests.yaml
vendored
@@ -1,98 +0,0 @@
|
|||||||
name: Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
# edtited - because base branch can be modified
|
|
||||||
# synchronize - update commits on PR
|
|
||||||
types: [opened, synchronize, edited]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ ubuntu-latest, macos-latest ]
|
|
||||||
name: Tests, ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: Fix CRLF on Windows
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: git config --global core.autocrlf false
|
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# Increase the pagefile size on Windows to aviod running out of memory
|
|
||||||
- name: Increase pagefile size on Windows
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: powershell -command .github\workflows\SetPageFileSize.ps1
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
|
|
||||||
|
|
||||||
# Source: https://github.com/actions/cache/blob/main/examples.md#go---modules
|
|
||||||
- name: Go Cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
shell: bash
|
|
||||||
run: ./build_and_test.sh -v
|
|
||||||
|
|
||||||
|
|
||||||
stability-test-fast:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Fast stability tests, ${{ github.head_ref }}
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Install kaspad
|
|
||||||
run: go install ./...
|
|
||||||
|
|
||||||
- name: Install golint
|
|
||||||
run: go get -u golang.org/x/lint/golint
|
|
||||||
|
|
||||||
- name: Run fast stability tests
|
|
||||||
working-directory: stability-tests
|
|
||||||
run: ./install_and_test.sh
|
|
||||||
|
|
||||||
|
|
||||||
coverage:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Produce code coverage
|
|
||||||
steps:
|
|
||||||
- name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.16
|
|
||||||
|
|
||||||
- name: Delete the stability tests from coverage
|
|
||||||
run: rm -r stability-tests
|
|
||||||
|
|
||||||
- name: Create coverage file
|
|
||||||
run: go test -v -covermode=atomic -coverpkg=./... -coverprofile coverage.txt ./...
|
|
||||||
|
|
||||||
- name: Upload coverage file
|
|
||||||
run: bash <(curl -s https://codecov.io/bash)
|
|
||||||
@@ -56,15 +56,13 @@ $ kaspad
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Discord
|
## Discord
|
||||||
Join our discord server using the following link: https://discord.gg/YNYnNN5Pf2
|
Join our discord server using the following link: https://discord.gg/WmGhhzk
|
||||||
|
|
||||||
## Issue Tracker
|
## Issue Tracker
|
||||||
|
|
||||||
The [integrated github issue tracker](https://github.com/kaspanet/kaspad/issues)
|
The [integrated github issue tracker](https://github.com/kaspanet/kaspad/issues)
|
||||||
is used for this project.
|
is used for this project.
|
||||||
|
|
||||||
Issue priorities may be seen at https://github.com/orgs/kaspanet/projects/4
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The [documentation](https://github.com/kaspanet/docs) is a work-in-progress
|
The [documentation](https://github.com/kaspanet/docs) is a work-in-progress
|
||||||
|
|||||||
29
app/app.go
29
app/app.go
@@ -85,6 +85,12 @@ func (app *kaspadApp) main(startedChan chan<- struct{}) error {
|
|||||||
profiling.Start(app.cfg.Profile, log)
|
profiling.Start(app.cfg.Profile, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Perform upgrades to kaspad as new versions require it.
|
||||||
|
if err := doUpgrades(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Return now if an interrupt signal was triggered.
|
// Return now if an interrupt signal was triggered.
|
||||||
if signal.InterruptRequested(interrupt) {
|
if signal.InterruptRequested(interrupt) {
|
||||||
return nil
|
return nil
|
||||||
@@ -101,7 +107,7 @@ func (app *kaspadApp) main(startedChan chan<- struct{}) error {
|
|||||||
// Open the database
|
// Open the database
|
||||||
databaseContext, err := openDB(app.cfg)
|
databaseContext, err := openDB(app.cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Loading database failed: %+v", err)
|
log.Error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +163,15 @@ func (app *kaspadApp) main(startedChan chan<- struct{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// doUpgrades performs upgrades to kaspad as new versions require it.
|
||||||
|
// currently it's a placeholder we got from kaspad upstream, that does nothing
|
||||||
|
func doUpgrades() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// dbPath returns the path to the block database given a database type.
|
// dbPath returns the path to the block database given a database type.
|
||||||
func databasePath(cfg *config.Config) string {
|
func databasePath(cfg *config.Config) string {
|
||||||
return filepath.Join(cfg.AppDir, "data")
|
return filepath.Join(cfg.DataDir, "db")
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeDatabase(cfg *config.Config) error {
|
func removeDatabase(cfg *config.Config) error {
|
||||||
@@ -169,17 +181,6 @@ func removeDatabase(cfg *config.Config) error {
|
|||||||
|
|
||||||
func openDB(cfg *config.Config) (database.Database, error) {
|
func openDB(cfg *config.Config) (database.Database, error) {
|
||||||
dbPath := databasePath(cfg)
|
dbPath := databasePath(cfg)
|
||||||
|
|
||||||
err := checkDatabaseVersion(dbPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Loading database from '%s'", dbPath)
|
log.Infof("Loading database from '%s'", dbPath)
|
||||||
db, err := ldb.NewLevelDB(dbPath, leveldbCacheSizeMiB)
|
return ldb.NewLevelDB(dbPath, leveldbCacheSizeMiB)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ package appmessage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/blockheader"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/blockheader"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/utxo"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/utxo"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
@@ -31,17 +27,13 @@ func DomainBlockToMsgBlock(domainBlock *externalapi.DomainBlock) *MsgBlock {
|
|||||||
func DomainBlockHeaderToBlockHeader(domainBlockHeader externalapi.BlockHeader) *MsgBlockHeader {
|
func DomainBlockHeaderToBlockHeader(domainBlockHeader externalapi.BlockHeader) *MsgBlockHeader {
|
||||||
return &MsgBlockHeader{
|
return &MsgBlockHeader{
|
||||||
Version: domainBlockHeader.Version(),
|
Version: domainBlockHeader.Version(),
|
||||||
Parents: domainBlockHeader.Parents(),
|
ParentHashes: domainBlockHeader.ParentHashes(),
|
||||||
HashMerkleRoot: domainBlockHeader.HashMerkleRoot(),
|
HashMerkleRoot: domainBlockHeader.HashMerkleRoot(),
|
||||||
AcceptedIDMerkleRoot: domainBlockHeader.AcceptedIDMerkleRoot(),
|
AcceptedIDMerkleRoot: domainBlockHeader.AcceptedIDMerkleRoot(),
|
||||||
UTXOCommitment: domainBlockHeader.UTXOCommitment(),
|
UTXOCommitment: domainBlockHeader.UTXOCommitment(),
|
||||||
Timestamp: mstime.UnixMilliseconds(domainBlockHeader.TimeInMilliseconds()),
|
Timestamp: mstime.UnixMilliseconds(domainBlockHeader.TimeInMilliseconds()),
|
||||||
Bits: domainBlockHeader.Bits(),
|
Bits: domainBlockHeader.Bits(),
|
||||||
Nonce: domainBlockHeader.Nonce(),
|
Nonce: domainBlockHeader.Nonce(),
|
||||||
BlueScore: domainBlockHeader.BlueScore(),
|
|
||||||
DAAScore: domainBlockHeader.DAAScore(),
|
|
||||||
BlueWork: domainBlockHeader.BlueWork(),
|
|
||||||
PruningPoint: domainBlockHeader.PruningPoint(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,17 +54,13 @@ func MsgBlockToDomainBlock(msgBlock *MsgBlock) *externalapi.DomainBlock {
|
|||||||
func BlockHeaderToDomainBlockHeader(blockHeader *MsgBlockHeader) externalapi.BlockHeader {
|
func BlockHeaderToDomainBlockHeader(blockHeader *MsgBlockHeader) externalapi.BlockHeader {
|
||||||
return blockheader.NewImmutableBlockHeader(
|
return blockheader.NewImmutableBlockHeader(
|
||||||
blockHeader.Version,
|
blockHeader.Version,
|
||||||
blockHeader.Parents,
|
blockHeader.ParentHashes,
|
||||||
blockHeader.HashMerkleRoot,
|
blockHeader.HashMerkleRoot,
|
||||||
blockHeader.AcceptedIDMerkleRoot,
|
blockHeader.AcceptedIDMerkleRoot,
|
||||||
blockHeader.UTXOCommitment,
|
blockHeader.UTXOCommitment,
|
||||||
blockHeader.Timestamp.UnixMilliseconds(),
|
blockHeader.Timestamp.UnixMilliseconds(),
|
||||||
blockHeader.Bits,
|
blockHeader.Bits,
|
||||||
blockHeader.Nonce,
|
blockHeader.Nonce,
|
||||||
blockHeader.DAAScore,
|
|
||||||
blockHeader.BlueScore,
|
|
||||||
blockHeader.BlueWork,
|
|
||||||
blockHeader.PruningPoint,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +83,7 @@ func DomainTransactionToMsgTx(domainTransaction *externalapi.DomainTransaction)
|
|||||||
LockTime: domainTransaction.LockTime,
|
LockTime: domainTransaction.LockTime,
|
||||||
SubnetworkID: domainTransaction.SubnetworkID,
|
SubnetworkID: domainTransaction.SubnetworkID,
|
||||||
Gas: domainTransaction.Gas,
|
Gas: domainTransaction.Gas,
|
||||||
|
PayloadHash: domainTransaction.PayloadHash,
|
||||||
Payload: domainTransaction.Payload,
|
Payload: domainTransaction.Payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +100,6 @@ func domainTransactionInputToTxIn(domainTransactionInput *externalapi.DomainTran
|
|||||||
PreviousOutpoint: *domainOutpointToOutpoint(domainTransactionInput.PreviousOutpoint),
|
PreviousOutpoint: *domainOutpointToOutpoint(domainTransactionInput.PreviousOutpoint),
|
||||||
SignatureScript: domainTransactionInput.SignatureScript,
|
SignatureScript: domainTransactionInput.SignatureScript,
|
||||||
Sequence: domainTransactionInput.Sequence,
|
Sequence: domainTransactionInput.Sequence,
|
||||||
SigOpCount: domainTransactionInput.SigOpCount,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +133,7 @@ func MsgTxToDomainTransaction(msgTx *MsgTx) *externalapi.DomainTransaction {
|
|||||||
LockTime: msgTx.LockTime,
|
LockTime: msgTx.LockTime,
|
||||||
SubnetworkID: msgTx.SubnetworkID,
|
SubnetworkID: msgTx.SubnetworkID,
|
||||||
Gas: msgTx.Gas,
|
Gas: msgTx.Gas,
|
||||||
|
PayloadHash: msgTx.PayloadHash,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,7 +149,6 @@ func txInToDomainTransactionInput(txIn *TxIn) *externalapi.DomainTransactionInpu
|
|||||||
return &externalapi.DomainTransactionInput{
|
return &externalapi.DomainTransactionInput{
|
||||||
PreviousOutpoint: *outpointToDomainOutpoint(&txIn.PreviousOutpoint), //TODO
|
PreviousOutpoint: *outpointToDomainOutpoint(&txIn.PreviousOutpoint), //TODO
|
||||||
SignatureScript: txIn.SignatureScript,
|
SignatureScript: txIn.SignatureScript,
|
||||||
SigOpCount: txIn.SigOpCount,
|
|
||||||
Sequence: txIn.Sequence,
|
Sequence: txIn.Sequence,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,10 +164,14 @@ func outpointToDomainOutpoint(outpoint *Outpoint) *externalapi.DomainOutpoint {
|
|||||||
func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externalapi.DomainTransaction, error) {
|
func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externalapi.DomainTransaction, error) {
|
||||||
inputs := make([]*externalapi.DomainTransactionInput, len(rpcTransaction.Inputs))
|
inputs := make([]*externalapi.DomainTransactionInput, len(rpcTransaction.Inputs))
|
||||||
for i, input := range rpcTransaction.Inputs {
|
for i, input := range rpcTransaction.Inputs {
|
||||||
previousOutpoint, err := RPCOutpointToDomainOutpoint(input.PreviousOutpoint)
|
transactionID, err := transactionid.FromString(input.PreviousOutpoint.TransactionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
previousOutpoint := &externalapi.DomainOutpoint{
|
||||||
|
TransactionID: *transactionID,
|
||||||
|
Index: input.PreviousOutpoint.Index,
|
||||||
|
}
|
||||||
signatureScript, err := hex.DecodeString(input.SignatureScript)
|
signatureScript, err := hex.DecodeString(input.SignatureScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -188,7 +180,6 @@ func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externa
|
|||||||
PreviousOutpoint: *previousOutpoint,
|
PreviousOutpoint: *previousOutpoint,
|
||||||
SignatureScript: signatureScript,
|
SignatureScript: signatureScript,
|
||||||
Sequence: input.Sequence,
|
Sequence: input.Sequence,
|
||||||
SigOpCount: input.SigOpCount,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outputs := make([]*externalapi.DomainTransactionOutput, len(rpcTransaction.Outputs))
|
outputs := make([]*externalapi.DomainTransactionOutput, len(rpcTransaction.Outputs))
|
||||||
@@ -207,6 +198,10 @@ func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
payloadHash, err := externalapi.NewDomainHashFromString(rpcTransaction.PayloadHash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
payload, err := hex.DecodeString(rpcTransaction.Payload)
|
payload, err := hex.DecodeString(rpcTransaction.Payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -219,40 +214,11 @@ func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externa
|
|||||||
LockTime: rpcTransaction.LockTime,
|
LockTime: rpcTransaction.LockTime,
|
||||||
SubnetworkID: *subnetworkID,
|
SubnetworkID: *subnetworkID,
|
||||||
Gas: rpcTransaction.LockTime,
|
Gas: rpcTransaction.LockTime,
|
||||||
|
PayloadHash: *payloadHash,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCOutpointToDomainOutpoint converts RPCOutpoint to DomainOutpoint
|
|
||||||
func RPCOutpointToDomainOutpoint(outpoint *RPCOutpoint) (*externalapi.DomainOutpoint, error) {
|
|
||||||
transactionID, err := transactionid.FromString(outpoint.TransactionID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &externalapi.DomainOutpoint{
|
|
||||||
TransactionID: *transactionID,
|
|
||||||
Index: outpoint.Index,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCUTXOEntryToUTXOEntry converts RPCUTXOEntry to UTXOEntry
|
|
||||||
func RPCUTXOEntryToUTXOEntry(entry *RPCUTXOEntry) (externalapi.UTXOEntry, error) {
|
|
||||||
script, err := hex.DecodeString(entry.ScriptPublicKey.Script)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return utxo.NewUTXOEntry(
|
|
||||||
entry.Amount,
|
|
||||||
&externalapi.ScriptPublicKey{
|
|
||||||
Script: script,
|
|
||||||
Version: entry.ScriptPublicKey.Version,
|
|
||||||
},
|
|
||||||
entry.IsCoinbase,
|
|
||||||
entry.BlockDAAScore,
|
|
||||||
), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DomainTransactionToRPCTransaction converts DomainTransactions to RPCTransactions
|
// DomainTransactionToRPCTransaction converts DomainTransactions to RPCTransactions
|
||||||
func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransaction) *RPCTransaction {
|
func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransaction) *RPCTransaction {
|
||||||
inputs := make([]*RPCTransactionInput, len(transaction.Inputs))
|
inputs := make([]*RPCTransactionInput, len(transaction.Inputs))
|
||||||
@@ -267,7 +233,6 @@ func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransactio
|
|||||||
PreviousOutpoint: previousOutpoint,
|
PreviousOutpoint: previousOutpoint,
|
||||||
SignatureScript: signatureScript,
|
SignatureScript: signatureScript,
|
||||||
Sequence: input.Sequence,
|
Sequence: input.Sequence,
|
||||||
SigOpCount: input.SigOpCount,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outputs := make([]*RPCTransactionOutput, len(transaction.Outputs))
|
outputs := make([]*RPCTransactionOutput, len(transaction.Outputs))
|
||||||
@@ -279,6 +244,7 @@ func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransactio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
subnetworkID := transaction.SubnetworkID.String()
|
subnetworkID := transaction.SubnetworkID.String()
|
||||||
|
payloadHash := transaction.PayloadHash.String()
|
||||||
payload := hex.EncodeToString(transaction.Payload)
|
payload := hex.EncodeToString(transaction.Payload)
|
||||||
return &RPCTransaction{
|
return &RPCTransaction{
|
||||||
Version: transaction.Version,
|
Version: transaction.Version,
|
||||||
@@ -287,6 +253,7 @@ func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransactio
|
|||||||
LockTime: transaction.LockTime,
|
LockTime: transaction.LockTime,
|
||||||
SubnetworkID: subnetworkID,
|
SubnetworkID: subnetworkID,
|
||||||
Gas: transaction.LockTime,
|
Gas: transaction.LockTime,
|
||||||
|
PayloadHash: payloadHash,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,27 +265,22 @@ func OutpointAndUTXOEntryPairsToDomainOutpointAndUTXOEntryPairs(
|
|||||||
|
|
||||||
domainOutpointAndUTXOEntryPairs := make([]*externalapi.OutpointAndUTXOEntryPair, len(outpointAndUTXOEntryPairs))
|
domainOutpointAndUTXOEntryPairs := make([]*externalapi.OutpointAndUTXOEntryPair, len(outpointAndUTXOEntryPairs))
|
||||||
for i, outpointAndUTXOEntryPair := range outpointAndUTXOEntryPairs {
|
for i, outpointAndUTXOEntryPair := range outpointAndUTXOEntryPairs {
|
||||||
domainOutpointAndUTXOEntryPairs[i] = outpointAndUTXOEntryPairToDomainOutpointAndUTXOEntryPair(outpointAndUTXOEntryPair)
|
domainOutpointAndUTXOEntryPairs[i] = &externalapi.OutpointAndUTXOEntryPair{
|
||||||
|
Outpoint: &externalapi.DomainOutpoint{
|
||||||
|
TransactionID: outpointAndUTXOEntryPair.Outpoint.TxID,
|
||||||
|
Index: outpointAndUTXOEntryPair.Outpoint.Index,
|
||||||
|
},
|
||||||
|
UTXOEntry: utxo.NewUTXOEntry(
|
||||||
|
outpointAndUTXOEntryPair.UTXOEntry.Amount,
|
||||||
|
outpointAndUTXOEntryPair.UTXOEntry.ScriptPublicKey,
|
||||||
|
outpointAndUTXOEntryPair.UTXOEntry.IsCoinbase,
|
||||||
|
outpointAndUTXOEntryPair.UTXOEntry.BlockBlueScore,
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return domainOutpointAndUTXOEntryPairs
|
return domainOutpointAndUTXOEntryPairs
|
||||||
}
|
}
|
||||||
|
|
||||||
func outpointAndUTXOEntryPairToDomainOutpointAndUTXOEntryPair(
|
|
||||||
outpointAndUTXOEntryPair *OutpointAndUTXOEntryPair) *externalapi.OutpointAndUTXOEntryPair {
|
|
||||||
return &externalapi.OutpointAndUTXOEntryPair{
|
|
||||||
Outpoint: &externalapi.DomainOutpoint{
|
|
||||||
TransactionID: outpointAndUTXOEntryPair.Outpoint.TxID,
|
|
||||||
Index: outpointAndUTXOEntryPair.Outpoint.Index,
|
|
||||||
},
|
|
||||||
UTXOEntry: utxo.NewUTXOEntry(
|
|
||||||
outpointAndUTXOEntryPair.UTXOEntry.Amount,
|
|
||||||
outpointAndUTXOEntryPair.UTXOEntry.ScriptPublicKey,
|
|
||||||
outpointAndUTXOEntryPair.UTXOEntry.IsCoinbase,
|
|
||||||
outpointAndUTXOEntryPair.UTXOEntry.BlockDAAScore,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs converts
|
// DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs converts
|
||||||
// domain OutpointAndUTXOEntryPairs to OutpointAndUTXOEntryPairs
|
// domain OutpointAndUTXOEntryPairs to OutpointAndUTXOEntryPairs
|
||||||
func DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs(
|
func DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs(
|
||||||
@@ -335,216 +297,9 @@ func DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs(
|
|||||||
Amount: outpointAndUTXOEntryPair.UTXOEntry.Amount(),
|
Amount: outpointAndUTXOEntryPair.UTXOEntry.Amount(),
|
||||||
ScriptPublicKey: outpointAndUTXOEntryPair.UTXOEntry.ScriptPublicKey(),
|
ScriptPublicKey: outpointAndUTXOEntryPair.UTXOEntry.ScriptPublicKey(),
|
||||||
IsCoinbase: outpointAndUTXOEntryPair.UTXOEntry.IsCoinbase(),
|
IsCoinbase: outpointAndUTXOEntryPair.UTXOEntry.IsCoinbase(),
|
||||||
BlockDAAScore: outpointAndUTXOEntryPair.UTXOEntry.BlockDAAScore(),
|
BlockBlueScore: outpointAndUTXOEntryPair.UTXOEntry.BlockBlueScore(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return domainOutpointAndUTXOEntryPairs
|
return domainOutpointAndUTXOEntryPairs
|
||||||
}
|
}
|
||||||
|
|
||||||
// DomainBlockToRPCBlock converts DomainBlocks to RPCBlocks
|
|
||||||
func DomainBlockToRPCBlock(block *externalapi.DomainBlock) *RPCBlock {
|
|
||||||
parents := make([]*RPCBlockLevelParents, len(block.Header.Parents()))
|
|
||||||
for i, blockLevelParents := range block.Header.Parents() {
|
|
||||||
parents[i] = &RPCBlockLevelParents{
|
|
||||||
ParentHashes: hashes.ToStrings(blockLevelParents),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header := &RPCBlockHeader{
|
|
||||||
Version: uint32(block.Header.Version()),
|
|
||||||
Parents: parents,
|
|
||||||
HashMerkleRoot: block.Header.HashMerkleRoot().String(),
|
|
||||||
AcceptedIDMerkleRoot: block.Header.AcceptedIDMerkleRoot().String(),
|
|
||||||
UTXOCommitment: block.Header.UTXOCommitment().String(),
|
|
||||||
Timestamp: block.Header.TimeInMilliseconds(),
|
|
||||||
Bits: block.Header.Bits(),
|
|
||||||
Nonce: block.Header.Nonce(),
|
|
||||||
DAAScore: block.Header.DAAScore(),
|
|
||||||
BlueScore: block.Header.BlueScore(),
|
|
||||||
BlueWork: block.Header.BlueWork().Text(16),
|
|
||||||
PruningPoint: block.Header.PruningPoint().String(),
|
|
||||||
}
|
|
||||||
transactions := make([]*RPCTransaction, len(block.Transactions))
|
|
||||||
for i, transaction := range block.Transactions {
|
|
||||||
transactions[i] = DomainTransactionToRPCTransaction(transaction)
|
|
||||||
}
|
|
||||||
return &RPCBlock{
|
|
||||||
Header: header,
|
|
||||||
Transactions: transactions,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCBlockToDomainBlock converts `block` into a DomainBlock
|
|
||||||
func RPCBlockToDomainBlock(block *RPCBlock) (*externalapi.DomainBlock, error) {
|
|
||||||
parents := make([]externalapi.BlockLevelParents, len(block.Header.Parents))
|
|
||||||
for i, blockLevelParents := range block.Header.Parents {
|
|
||||||
parents[i] = make(externalapi.BlockLevelParents, len(blockLevelParents.ParentHashes))
|
|
||||||
for j, parentHash := range blockLevelParents.ParentHashes {
|
|
||||||
var err error
|
|
||||||
parents[i][j], err = externalapi.NewDomainHashFromString(parentHash)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hashMerkleRoot, err := externalapi.NewDomainHashFromString(block.Header.HashMerkleRoot)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
acceptedIDMerkleRoot, err := externalapi.NewDomainHashFromString(block.Header.AcceptedIDMerkleRoot)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
utxoCommitment, err := externalapi.NewDomainHashFromString(block.Header.UTXOCommitment)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
blueWork, success := new(big.Int).SetString(block.Header.BlueWork, 16)
|
|
||||||
if !success {
|
|
||||||
return nil, errors.Errorf("failed to parse blue work: %s", block.Header.BlueWork)
|
|
||||||
}
|
|
||||||
pruningPoint, err := externalapi.NewDomainHashFromString(block.Header.PruningPoint)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
header := blockheader.NewImmutableBlockHeader(
|
|
||||||
uint16(block.Header.Version),
|
|
||||||
parents,
|
|
||||||
hashMerkleRoot,
|
|
||||||
acceptedIDMerkleRoot,
|
|
||||||
utxoCommitment,
|
|
||||||
block.Header.Timestamp,
|
|
||||||
block.Header.Bits,
|
|
||||||
block.Header.Nonce,
|
|
||||||
block.Header.DAAScore,
|
|
||||||
block.Header.BlueScore,
|
|
||||||
blueWork,
|
|
||||||
pruningPoint)
|
|
||||||
transactions := make([]*externalapi.DomainTransaction, len(block.Transactions))
|
|
||||||
for i, transaction := range block.Transactions {
|
|
||||||
domainTransaction, err := RPCTransactionToDomainTransaction(transaction)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
transactions[i] = domainTransaction
|
|
||||||
}
|
|
||||||
return &externalapi.DomainBlock{
|
|
||||||
Header: header,
|
|
||||||
Transactions: transactions,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockWithTrustedDataToDomainBlockWithTrustedData converts *MsgBlockWithTrustedData to *externalapi.BlockWithTrustedData
|
|
||||||
func BlockWithTrustedDataToDomainBlockWithTrustedData(block *MsgBlockWithTrustedData) *externalapi.BlockWithTrustedData {
|
|
||||||
daaWindow := make([]*externalapi.TrustedDataDataDAABlock, len(block.DAAWindow))
|
|
||||||
for i, daaBlock := range block.DAAWindow {
|
|
||||||
daaWindow[i] = &externalapi.TrustedDataDataDAABlock{
|
|
||||||
Block: MsgBlockToDomainBlock(daaBlock.Block),
|
|
||||||
GHOSTDAGData: ghostdagDataToDomainGHOSTDAGData(daaBlock.GHOSTDAGData),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ghostdagData := make([]*externalapi.BlockGHOSTDAGDataHashPair, len(block.GHOSTDAGData))
|
|
||||||
for i, datum := range block.GHOSTDAGData {
|
|
||||||
ghostdagData[i] = &externalapi.BlockGHOSTDAGDataHashPair{
|
|
||||||
Hash: datum.Hash,
|
|
||||||
GHOSTDAGData: ghostdagDataToDomainGHOSTDAGData(datum.GHOSTDAGData),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &externalapi.BlockWithTrustedData{
|
|
||||||
Block: MsgBlockToDomainBlock(block.Block),
|
|
||||||
DAAScore: block.DAAScore,
|
|
||||||
DAAWindow: daaWindow,
|
|
||||||
GHOSTDAGData: ghostdagData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ghostdagDataToDomainGHOSTDAGData(data *BlockGHOSTDAGData) *externalapi.BlockGHOSTDAGData {
|
|
||||||
bluesAnticoneSizes := make(map[externalapi.DomainHash]externalapi.KType, len(data.BluesAnticoneSizes))
|
|
||||||
for _, pair := range data.BluesAnticoneSizes {
|
|
||||||
bluesAnticoneSizes[*pair.BlueHash] = pair.AnticoneSize
|
|
||||||
}
|
|
||||||
return externalapi.NewBlockGHOSTDAGData(
|
|
||||||
data.BlueScore,
|
|
||||||
data.BlueWork,
|
|
||||||
data.SelectedParent,
|
|
||||||
data.MergeSetBlues,
|
|
||||||
data.MergeSetReds,
|
|
||||||
bluesAnticoneSizes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func domainGHOSTDAGDataGHOSTDAGData(data *externalapi.BlockGHOSTDAGData) *BlockGHOSTDAGData {
|
|
||||||
bluesAnticoneSizes := make([]*BluesAnticoneSizes, 0, len(data.BluesAnticoneSizes()))
|
|
||||||
for blueHash, anticoneSize := range data.BluesAnticoneSizes() {
|
|
||||||
blueHashCopy := blueHash
|
|
||||||
bluesAnticoneSizes = append(bluesAnticoneSizes, &BluesAnticoneSizes{
|
|
||||||
BlueHash: &blueHashCopy,
|
|
||||||
AnticoneSize: anticoneSize,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return &BlockGHOSTDAGData{
|
|
||||||
BlueScore: data.BlueScore(),
|
|
||||||
BlueWork: data.BlueWork(),
|
|
||||||
SelectedParent: data.SelectedParent(),
|
|
||||||
MergeSetBlues: data.MergeSetBlues(),
|
|
||||||
MergeSetReds: data.MergeSetReds(),
|
|
||||||
BluesAnticoneSizes: bluesAnticoneSizes,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DomainBlockWithTrustedDataToBlockWithTrustedData converts *externalapi.BlockWithTrustedData to *MsgBlockWithTrustedData
|
|
||||||
func DomainBlockWithTrustedDataToBlockWithTrustedData(block *externalapi.BlockWithTrustedData) *MsgBlockWithTrustedData {
|
|
||||||
daaWindow := make([]*TrustedDataDataDAABlock, len(block.DAAWindow))
|
|
||||||
for i, daaBlock := range block.DAAWindow {
|
|
||||||
daaWindow[i] = &TrustedDataDataDAABlock{
|
|
||||||
Block: DomainBlockToMsgBlock(daaBlock.Block),
|
|
||||||
GHOSTDAGData: domainGHOSTDAGDataGHOSTDAGData(daaBlock.GHOSTDAGData),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ghostdagData := make([]*BlockGHOSTDAGDataHashPair, len(block.GHOSTDAGData))
|
|
||||||
for i, datum := range block.GHOSTDAGData {
|
|
||||||
ghostdagData[i] = &BlockGHOSTDAGDataHashPair{
|
|
||||||
Hash: datum.Hash,
|
|
||||||
GHOSTDAGData: domainGHOSTDAGDataGHOSTDAGData(datum.GHOSTDAGData),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &MsgBlockWithTrustedData{
|
|
||||||
Block: DomainBlockToMsgBlock(block.Block),
|
|
||||||
DAAScore: block.DAAScore,
|
|
||||||
DAAWindow: daaWindow,
|
|
||||||
GHOSTDAGData: ghostdagData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MsgPruningPointProofToDomainPruningPointProof converts *MsgPruningPointProof to *externalapi.PruningPointProof
|
|
||||||
func MsgPruningPointProofToDomainPruningPointProof(pruningPointProofMessage *MsgPruningPointProof) *externalapi.PruningPointProof {
|
|
||||||
headers := make([][]externalapi.BlockHeader, len(pruningPointProofMessage.Headers))
|
|
||||||
for blockLevel, blockLevelParents := range pruningPointProofMessage.Headers {
|
|
||||||
headers[blockLevel] = make([]externalapi.BlockHeader, len(blockLevelParents))
|
|
||||||
for i, header := range blockLevelParents {
|
|
||||||
headers[blockLevel][i] = BlockHeaderToDomainBlockHeader(header)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &externalapi.PruningPointProof{
|
|
||||||
Headers: headers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DomainPruningPointProofToMsgPruningPointProof converts *externalapi.PruningPointProof to *MsgPruningPointProof
|
|
||||||
func DomainPruningPointProofToMsgPruningPointProof(pruningPointProof *externalapi.PruningPointProof) *MsgPruningPointProof {
|
|
||||||
headers := make([][]*MsgBlockHeader, len(pruningPointProof.Headers))
|
|
||||||
for blockLevel, blockLevelParents := range pruningPointProof.Headers {
|
|
||||||
headers[blockLevel] = make([]*MsgBlockHeader, len(blockLevelParents))
|
|
||||||
for i, header := range blockLevelParents {
|
|
||||||
headers[blockLevel][i] = DomainBlockHeaderToBlockHeader(header)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &MsgPruningPointProof{
|
|
||||||
Headers: headers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,27 +45,24 @@ const (
|
|||||||
CmdRequestRelayBlocks
|
CmdRequestRelayBlocks
|
||||||
CmdInvTransaction
|
CmdInvTransaction
|
||||||
CmdRequestTransactions
|
CmdRequestTransactions
|
||||||
|
CmdIBDBlock
|
||||||
CmdDoneHeaders
|
CmdDoneHeaders
|
||||||
CmdTransactionNotFound
|
CmdTransactionNotFound
|
||||||
CmdReject
|
CmdReject
|
||||||
|
CmdHeader
|
||||||
CmdRequestNextHeaders
|
CmdRequestNextHeaders
|
||||||
CmdRequestPruningPointUTXOSet
|
CmdRequestPruningPointUTXOSetAndBlock
|
||||||
CmdPruningPointUTXOSetChunk
|
CmdPruningPointUTXOSetChunk
|
||||||
|
CmdRequestIBDBlocks
|
||||||
CmdUnexpectedPruningPoint
|
CmdUnexpectedPruningPoint
|
||||||
|
CmdRequestPruningPointHash
|
||||||
|
CmdPruningPointHash
|
||||||
CmdIBDBlockLocator
|
CmdIBDBlockLocator
|
||||||
CmdIBDBlockLocatorHighestHash
|
CmdIBDBlockLocatorHighestHash
|
||||||
CmdIBDBlockLocatorHighestHashNotFound
|
CmdIBDBlockLocatorHighestHashNotFound
|
||||||
CmdBlockHeaders
|
CmdBlockHeaders
|
||||||
CmdRequestNextPruningPointUTXOSetChunk
|
CmdRequestNextPruningPointUTXOSetChunk
|
||||||
CmdDonePruningPointUTXOSetChunks
|
CmdDonePruningPointUTXOSetChunks
|
||||||
CmdBlockWithTrustedData
|
|
||||||
CmdDoneBlocksWithTrustedData
|
|
||||||
CmdRequestPruningPointAndItsAnticone
|
|
||||||
CmdIBDBlock
|
|
||||||
CmdRequestIBDBlocks
|
|
||||||
CmdPruningPoints
|
|
||||||
CmdRequestPruningPointProof
|
|
||||||
CmdPruningPointProof
|
|
||||||
|
|
||||||
// rpc
|
// rpc
|
||||||
CmdGetCurrentNetworkRequestMessage
|
CmdGetCurrentNetworkRequestMessage
|
||||||
@@ -140,11 +137,6 @@ const (
|
|||||||
CmdPruningPointUTXOSetOverrideNotificationMessage
|
CmdPruningPointUTXOSetOverrideNotificationMessage
|
||||||
CmdStopNotifyingPruningPointUTXOSetOverrideRequestMessage
|
CmdStopNotifyingPruningPointUTXOSetOverrideRequestMessage
|
||||||
CmdStopNotifyingPruningPointUTXOSetOverrideResponseMessage
|
CmdStopNotifyingPruningPointUTXOSetOverrideResponseMessage
|
||||||
CmdEstimateNetworkHashesPerSecondRequestMessage
|
|
||||||
CmdEstimateNetworkHashesPerSecondResponseMessage
|
|
||||||
CmdNotifyVirtualDaaScoreChangedRequestMessage
|
|
||||||
CmdNotifyVirtualDaaScoreChangedResponseMessage
|
|
||||||
CmdVirtualDaaScoreChangedNotificationMessage
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProtocolMessageCommandToString maps all MessageCommands to their string representation
|
// ProtocolMessageCommandToString maps all MessageCommands to their string representation
|
||||||
@@ -153,7 +145,7 @@ var ProtocolMessageCommandToString = map[MessageCommand]string{
|
|||||||
CmdVerAck: "VerAck",
|
CmdVerAck: "VerAck",
|
||||||
CmdRequestAddresses: "RequestAddresses",
|
CmdRequestAddresses: "RequestAddresses",
|
||||||
CmdAddresses: "Addresses",
|
CmdAddresses: "Addresses",
|
||||||
CmdRequestHeaders: "CmdRequestHeaders",
|
CmdRequestHeaders: "RequestHeaders",
|
||||||
CmdBlock: "Block",
|
CmdBlock: "Block",
|
||||||
CmdTx: "Tx",
|
CmdTx: "Tx",
|
||||||
CmdPing: "Ping",
|
CmdPing: "Ping",
|
||||||
@@ -164,27 +156,24 @@ var ProtocolMessageCommandToString = map[MessageCommand]string{
|
|||||||
CmdRequestRelayBlocks: "RequestRelayBlocks",
|
CmdRequestRelayBlocks: "RequestRelayBlocks",
|
||||||
CmdInvTransaction: "InvTransaction",
|
CmdInvTransaction: "InvTransaction",
|
||||||
CmdRequestTransactions: "RequestTransactions",
|
CmdRequestTransactions: "RequestTransactions",
|
||||||
|
CmdIBDBlock: "IBDBlock",
|
||||||
CmdDoneHeaders: "DoneHeaders",
|
CmdDoneHeaders: "DoneHeaders",
|
||||||
CmdTransactionNotFound: "TransactionNotFound",
|
CmdTransactionNotFound: "TransactionNotFound",
|
||||||
CmdReject: "Reject",
|
CmdReject: "Reject",
|
||||||
|
CmdHeader: "Header",
|
||||||
CmdRequestNextHeaders: "RequestNextHeaders",
|
CmdRequestNextHeaders: "RequestNextHeaders",
|
||||||
CmdRequestPruningPointUTXOSet: "RequestPruningPointUTXOSet",
|
CmdRequestPruningPointUTXOSetAndBlock: "RequestPruningPointUTXOSetAndBlock",
|
||||||
CmdPruningPointUTXOSetChunk: "PruningPointUTXOSetChunk",
|
CmdPruningPointUTXOSetChunk: "PruningPointUTXOSetChunk",
|
||||||
|
CmdRequestIBDBlocks: "RequestIBDBlocks",
|
||||||
CmdUnexpectedPruningPoint: "UnexpectedPruningPoint",
|
CmdUnexpectedPruningPoint: "UnexpectedPruningPoint",
|
||||||
|
CmdRequestPruningPointHash: "RequestPruningPointHashHash",
|
||||||
|
CmdPruningPointHash: "PruningPointHash",
|
||||||
CmdIBDBlockLocator: "IBDBlockLocator",
|
CmdIBDBlockLocator: "IBDBlockLocator",
|
||||||
CmdIBDBlockLocatorHighestHash: "IBDBlockLocatorHighestHash",
|
CmdIBDBlockLocatorHighestHash: "IBDBlockLocatorHighestHash",
|
||||||
CmdIBDBlockLocatorHighestHashNotFound: "IBDBlockLocatorHighestHashNotFound",
|
CmdIBDBlockLocatorHighestHashNotFound: "IBDBlockLocatorHighestHashNotFound",
|
||||||
CmdBlockHeaders: "BlockHeaders",
|
CmdBlockHeaders: "BlockHeaders",
|
||||||
CmdRequestNextPruningPointUTXOSetChunk: "RequestNextPruningPointUTXOSetChunk",
|
CmdRequestNextPruningPointUTXOSetChunk: "RequestNextPruningPointUTXOSetChunk",
|
||||||
CmdDonePruningPointUTXOSetChunks: "DonePruningPointUTXOSetChunks",
|
CmdDonePruningPointUTXOSetChunks: "DonePruningPointUTXOSetChunks",
|
||||||
CmdBlockWithTrustedData: "BlockWithTrustedData",
|
|
||||||
CmdDoneBlocksWithTrustedData: "DoneBlocksWithTrustedData",
|
|
||||||
CmdRequestPruningPointAndItsAnticone: "RequestPruningPointAndItsAnticoneHeaders",
|
|
||||||
CmdIBDBlock: "IBDBlock",
|
|
||||||
CmdRequestIBDBlocks: "RequestIBDBlocks",
|
|
||||||
CmdPruningPoints: "PruningPoints",
|
|
||||||
CmdRequestPruningPointProof: "RequestPruningPointProof",
|
|
||||||
CmdPruningPointProof: "PruningPointProof",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCMessageCommandToString maps all MessageCommands to their string representation
|
// RPCMessageCommandToString maps all MessageCommands to their string representation
|
||||||
@@ -259,11 +248,6 @@ var RPCMessageCommandToString = map[MessageCommand]string{
|
|||||||
CmdPruningPointUTXOSetOverrideNotificationMessage: "PruningPointUTXOSetOverrideNotification",
|
CmdPruningPointUTXOSetOverrideNotificationMessage: "PruningPointUTXOSetOverrideNotification",
|
||||||
CmdStopNotifyingPruningPointUTXOSetOverrideRequestMessage: "StopNotifyingPruningPointUTXOSetOverrideRequest",
|
CmdStopNotifyingPruningPointUTXOSetOverrideRequestMessage: "StopNotifyingPruningPointUTXOSetOverrideRequest",
|
||||||
CmdStopNotifyingPruningPointUTXOSetOverrideResponseMessage: "StopNotifyingPruningPointUTXOSetOverrideResponse",
|
CmdStopNotifyingPruningPointUTXOSetOverrideResponseMessage: "StopNotifyingPruningPointUTXOSetOverrideResponse",
|
||||||
CmdEstimateNetworkHashesPerSecondRequestMessage: "EstimateNetworkHashesPerSecondRequest",
|
|
||||||
CmdEstimateNetworkHashesPerSecondResponseMessage: "EstimateNetworkHashesPerSecondResponse",
|
|
||||||
CmdNotifyVirtualDaaScoreChangedRequestMessage: "NotifyVirtualDaaScoreChangedRequest",
|
|
||||||
CmdNotifyVirtualDaaScoreChangedResponseMessage: "NotifyVirtualDaaScoreChangedResponse",
|
|
||||||
CmdVirtualDaaScoreChangedNotificationMessage: "VirtualDaaScoreChangedNotification",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message is an interface that describes a kaspa message. A type that
|
// Message is an interface that describes a kaspa message. A type that
|
||||||
|
|||||||
@@ -15,6 +15,19 @@ import (
|
|||||||
// backing array multiple times.
|
// backing array multiple times.
|
||||||
const defaultTransactionAlloc = 2048
|
const defaultTransactionAlloc = 2048
|
||||||
|
|
||||||
|
// MaxMassAcceptedByBlock is the maximum total transaction mass a block may accept.
|
||||||
|
const MaxMassAcceptedByBlock = 10000000
|
||||||
|
|
||||||
|
// MaxMassPerTx is the maximum total mass a transaction may have.
|
||||||
|
const MaxMassPerTx = MaxMassAcceptedByBlock / 2
|
||||||
|
|
||||||
|
// MaxTxPerBlock is the maximum number of transactions that could
|
||||||
|
// possibly fit into a block.
|
||||||
|
const MaxTxPerBlock = (MaxMassAcceptedByBlock / minTxPayload) + 1
|
||||||
|
|
||||||
|
// MaxBlockParents is the maximum allowed number of parents for block.
|
||||||
|
const MaxBlockParents = 10
|
||||||
|
|
||||||
// TxLoc holds locator data for the offset and length of where a transaction is
|
// TxLoc holds locator data for the offset and length of where a transaction is
|
||||||
// located within a MsgBlock data buffer.
|
// located within a MsgBlock data buffer.
|
||||||
type TxLoc struct {
|
type TxLoc struct {
|
||||||
|
|||||||
@@ -21,18 +21,13 @@ func TestBlock(t *testing.T) {
|
|||||||
pver := ProtocolVersion
|
pver := ProtocolVersion
|
||||||
|
|
||||||
// Block 1 header.
|
// Block 1 header.
|
||||||
parents := blockOne.Header.Parents
|
parentHashes := blockOne.Header.ParentHashes
|
||||||
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||||
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||||
utxoCommitment := blockOne.Header.UTXOCommitment
|
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||||
bits := blockOne.Header.Bits
|
bits := blockOne.Header.Bits
|
||||||
nonce := blockOne.Header.Nonce
|
nonce := blockOne.Header.Nonce
|
||||||
daaScore := blockOne.Header.DAAScore
|
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||||
blueScore := blockOne.Header.BlueScore
|
|
||||||
blueWork := blockOne.Header.BlueWork
|
|
||||||
pruningPoint := blockOne.Header.PruningPoint
|
|
||||||
bh := NewBlockHeader(1, parents, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce,
|
|
||||||
daaScore, blueScore, blueWork, pruningPoint)
|
|
||||||
|
|
||||||
// Ensure the command is expected value.
|
// Ensure the command is expected value.
|
||||||
wantCmd := MessageCommand(5)
|
wantCmd := MessageCommand(5)
|
||||||
@@ -136,7 +131,7 @@ func TestConvertToPartial(t *testing.T) {
|
|||||||
var blockOne = MsgBlock{
|
var blockOne = MsgBlock{
|
||||||
Header: MsgBlockHeader{
|
Header: MsgBlockHeader{
|
||||||
Version: 0,
|
Version: 0,
|
||||||
Parents: []externalapi.BlockLevelParents{[]*externalapi.DomainHash{mainnetGenesisHash, simnetGenesisHash}},
|
ParentHashes: []*externalapi.DomainHash{mainnetGenesisHash, simnetGenesisHash},
|
||||||
HashMerkleRoot: mainnetGenesisMerkleRoot,
|
HashMerkleRoot: mainnetGenesisMerkleRoot,
|
||||||
AcceptedIDMerkleRoot: exampleAcceptedIDMerkleRoot,
|
AcceptedIDMerkleRoot: exampleAcceptedIDMerkleRoot,
|
||||||
UTXOCommitment: exampleUTXOCommitment,
|
UTXOCommitment: exampleUTXOCommitment,
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
package appmessage
|
package appmessage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/util/mstime"
|
"github.com/kaspanet/kaspad/util/mstime"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BaseBlockHeaderPayload is the base number of bytes a block header can be,
|
// BaseBlockHeaderPayload is the base number of bytes a block header can be,
|
||||||
@@ -38,8 +39,8 @@ type MsgBlockHeader struct {
|
|||||||
// Version of the block. This is not the same as the protocol version.
|
// Version of the block. This is not the same as the protocol version.
|
||||||
Version uint16
|
Version uint16
|
||||||
|
|
||||||
// Parents are the parent block hashes of the block in the DAG per superblock level.
|
// Hashes of the parent block headers in the blockDAG.
|
||||||
Parents []externalapi.BlockLevelParents
|
ParentHashes []*externalapi.DomainHash
|
||||||
|
|
||||||
// HashMerkleRoot is the merkle tree reference to hash of all transactions for the block.
|
// HashMerkleRoot is the merkle tree reference to hash of all transactions for the block.
|
||||||
HashMerkleRoot *externalapi.DomainHash
|
HashMerkleRoot *externalapi.DomainHash
|
||||||
@@ -59,16 +60,15 @@ type MsgBlockHeader struct {
|
|||||||
|
|
||||||
// Nonce used to generate the block.
|
// Nonce used to generate the block.
|
||||||
Nonce uint64
|
Nonce uint64
|
||||||
|
}
|
||||||
|
|
||||||
// DAASCore is the DAA score of the block.
|
// NumParentBlocks return the number of entries in ParentHashes
|
||||||
DAAScore uint64
|
func (h *MsgBlockHeader) NumParentBlocks() byte {
|
||||||
|
numParents := len(h.ParentHashes)
|
||||||
BlueScore uint64
|
if numParents > math.MaxUint8 {
|
||||||
|
panic(errors.Errorf("number of parents is %d, which is more than one byte can fit", numParents))
|
||||||
// BlueWork is the blue work of the block.
|
}
|
||||||
BlueWork *big.Int
|
return byte(numParents)
|
||||||
|
|
||||||
PruningPoint *externalapi.DomainHash
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockHash computes the block identifier hash for the given block header.
|
// BlockHash computes the block identifier hash for the given block header.
|
||||||
@@ -76,27 +76,33 @@ func (h *MsgBlockHeader) BlockHash() *externalapi.DomainHash {
|
|||||||
return consensushashing.HeaderHash(BlockHeaderToDomainBlockHeader(h))
|
return consensushashing.HeaderHash(BlockHeaderToDomainBlockHeader(h))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsGenesis returns true iff this block is a genesis block
|
||||||
|
func (h *MsgBlockHeader) IsGenesis() bool {
|
||||||
|
return h.NumParentBlocks() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command returns the protocol command string for the message. This is part
|
||||||
|
// of the Message interface implementation.
|
||||||
|
func (h *MsgBlockHeader) Command() MessageCommand {
|
||||||
|
return CmdHeader
|
||||||
|
}
|
||||||
|
|
||||||
// NewBlockHeader returns a new MsgBlockHeader using the provided version, previous
|
// NewBlockHeader returns a new MsgBlockHeader using the provided version, previous
|
||||||
// block hash, hash merkle root, accepted ID merkle root, difficulty bits, and nonce used to generate the
|
// block hash, hash merkle root, accepted ID merkle root, difficulty bits, and nonce used to generate the
|
||||||
// block with defaults or calclulated values for the remaining fields.
|
// block with defaults or calclulated values for the remaining fields.
|
||||||
func NewBlockHeader(version uint16, parents []externalapi.BlockLevelParents, hashMerkleRoot *externalapi.DomainHash,
|
func NewBlockHeader(version uint16, parentHashes []*externalapi.DomainHash, hashMerkleRoot *externalapi.DomainHash,
|
||||||
acceptedIDMerkleRoot *externalapi.DomainHash, utxoCommitment *externalapi.DomainHash, bits uint32, nonce,
|
acceptedIDMerkleRoot *externalapi.DomainHash, utxoCommitment *externalapi.DomainHash, bits uint32, nonce uint64) *MsgBlockHeader {
|
||||||
daaScore, blueScore uint64, blueWork *big.Int, pruningPoint *externalapi.DomainHash) *MsgBlockHeader {
|
|
||||||
|
|
||||||
// Limit the timestamp to one millisecond precision since the protocol
|
// Limit the timestamp to one millisecond precision since the protocol
|
||||||
// doesn't support better.
|
// doesn't support better.
|
||||||
return &MsgBlockHeader{
|
return &MsgBlockHeader{
|
||||||
Version: version,
|
Version: version,
|
||||||
Parents: parents,
|
ParentHashes: parentHashes,
|
||||||
HashMerkleRoot: hashMerkleRoot,
|
HashMerkleRoot: hashMerkleRoot,
|
||||||
AcceptedIDMerkleRoot: acceptedIDMerkleRoot,
|
AcceptedIDMerkleRoot: acceptedIDMerkleRoot,
|
||||||
UTXOCommitment: utxoCommitment,
|
UTXOCommitment: utxoCommitment,
|
||||||
Timestamp: mstime.Now(),
|
Timestamp: mstime.Now(),
|
||||||
Bits: bits,
|
Bits: bits,
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
DAAScore: daaScore,
|
|
||||||
BlueScore: blueScore,
|
|
||||||
BlueWork: blueWork,
|
|
||||||
PruningPoint: pruningPoint,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,34 +5,29 @@
|
|||||||
package appmessage
|
package appmessage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
"github.com/kaspanet/kaspad/util/mstime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestBlockHeader tests the MsgBlockHeader API.
|
// TestBlockHeader tests the MsgBlockHeader API.
|
||||||
func TestBlockHeader(t *testing.T) {
|
func TestBlockHeader(t *testing.T) {
|
||||||
nonce := uint64(0xba4d87a69924a93d)
|
nonce := uint64(0xba4d87a69924a93d)
|
||||||
|
|
||||||
parents := []externalapi.BlockLevelParents{[]*externalapi.DomainHash{mainnetGenesisHash, simnetGenesisHash}}
|
hashes := []*externalapi.DomainHash{mainnetGenesisHash, simnetGenesisHash}
|
||||||
|
|
||||||
merkleHash := mainnetGenesisMerkleRoot
|
merkleHash := mainnetGenesisMerkleRoot
|
||||||
acceptedIDMerkleRoot := exampleAcceptedIDMerkleRoot
|
acceptedIDMerkleRoot := exampleAcceptedIDMerkleRoot
|
||||||
bits := uint32(0x1d00ffff)
|
bits := uint32(0x1d00ffff)
|
||||||
daaScore := uint64(123)
|
bh := NewBlockHeader(1, hashes, merkleHash, acceptedIDMerkleRoot, exampleUTXOCommitment, bits, nonce)
|
||||||
blueScore := uint64(456)
|
|
||||||
blueWork := big.NewInt(789)
|
|
||||||
pruningPoint := simnetGenesisHash
|
|
||||||
bh := NewBlockHeader(1, parents, merkleHash, acceptedIDMerkleRoot, exampleUTXOCommitment, bits, nonce,
|
|
||||||
daaScore, blueScore, blueWork, pruningPoint)
|
|
||||||
|
|
||||||
// Ensure we get the same data back out.
|
// Ensure we get the same data back out.
|
||||||
if !reflect.DeepEqual(bh.Parents, parents) {
|
if !reflect.DeepEqual(bh.ParentHashes, hashes) {
|
||||||
t.Errorf("NewBlockHeader: wrong parents - got %v, want %v",
|
t.Errorf("NewBlockHeader: wrong prev hashes - got %v, want %v",
|
||||||
spew.Sprint(bh.Parents), spew.Sprint(parents))
|
spew.Sprint(bh.ParentHashes), spew.Sprint(hashes))
|
||||||
}
|
}
|
||||||
if bh.HashMerkleRoot != merkleHash {
|
if bh.HashMerkleRoot != merkleHash {
|
||||||
t.Errorf("NewBlockHeader: wrong merkle root - got %v, want %v",
|
t.Errorf("NewBlockHeader: wrong merkle root - got %v, want %v",
|
||||||
@@ -46,20 +41,44 @@ func TestBlockHeader(t *testing.T) {
|
|||||||
t.Errorf("NewBlockHeader: wrong nonce - got %v, want %v",
|
t.Errorf("NewBlockHeader: wrong nonce - got %v, want %v",
|
||||||
bh.Nonce, nonce)
|
bh.Nonce, nonce)
|
||||||
}
|
}
|
||||||
if bh.DAAScore != daaScore {
|
}
|
||||||
t.Errorf("NewBlockHeader: wrong daaScore - got %v, want %v",
|
|
||||||
bh.DAAScore, daaScore)
|
func TestIsGenesis(t *testing.T) {
|
||||||
|
nonce := uint64(123123) // 0x1e0f3
|
||||||
|
bits := uint32(0x1d00ffff)
|
||||||
|
timestamp := mstime.UnixMilliseconds(0x495fab29000)
|
||||||
|
|
||||||
|
baseBlockHdr := &MsgBlockHeader{
|
||||||
|
Version: 1,
|
||||||
|
ParentHashes: []*externalapi.DomainHash{mainnetGenesisHash, simnetGenesisHash},
|
||||||
|
HashMerkleRoot: mainnetGenesisMerkleRoot,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
Bits: bits,
|
||||||
|
Nonce: nonce,
|
||||||
}
|
}
|
||||||
if bh.BlueScore != blueScore {
|
genesisBlockHdr := &MsgBlockHeader{
|
||||||
t.Errorf("NewBlockHeader: wrong blueScore - got %v, want %v",
|
Version: 1,
|
||||||
bh.BlueScore, blueScore)
|
ParentHashes: []*externalapi.DomainHash{},
|
||||||
|
HashMerkleRoot: mainnetGenesisMerkleRoot,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
Bits: bits,
|
||||||
|
Nonce: nonce,
|
||||||
}
|
}
|
||||||
if bh.BlueWork != blueWork {
|
|
||||||
t.Errorf("NewBlockHeader: wrong blueWork - got %v, want %v",
|
tests := []struct {
|
||||||
bh.BlueWork, blueWork)
|
in *MsgBlockHeader // Block header to encode
|
||||||
|
isGenesis bool // Expected result for call of .IsGenesis
|
||||||
|
}{
|
||||||
|
{genesisBlockHdr, true},
|
||||||
|
{baseBlockHdr, false},
|
||||||
}
|
}
|
||||||
if !bh.PruningPoint.Equal(pruningPoint) {
|
|
||||||
t.Errorf("NewBlockHeader: wrong pruningPoint - got %v, want %v",
|
t.Logf("Running %d tests", len(tests))
|
||||||
bh.PruningPoint, pruningPoint)
|
for i, test := range tests {
|
||||||
|
isGenesis := test.in.IsGenesis()
|
||||||
|
if isGenesis != test.isGenesis {
|
||||||
|
t.Errorf("MsgBlockHeader.IsGenesis: #%d got: %t, want: %t",
|
||||||
|
i, isGenesis, test.isGenesis)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"math/big"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MsgBlockWithTrustedData represents a kaspa BlockWithTrustedData message
|
|
||||||
type MsgBlockWithTrustedData struct {
|
|
||||||
baseMessage
|
|
||||||
|
|
||||||
Block *MsgBlock
|
|
||||||
DAAScore uint64
|
|
||||||
DAAWindow []*TrustedDataDataDAABlock
|
|
||||||
GHOSTDAGData []*BlockGHOSTDAGDataHashPair
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *MsgBlockWithTrustedData) Command() MessageCommand {
|
|
||||||
return CmdBlockWithTrustedData
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgBlockWithTrustedData returns a new MsgBlockWithTrustedData.
|
|
||||||
func NewMsgBlockWithTrustedData() *MsgBlockWithTrustedData {
|
|
||||||
return &MsgBlockWithTrustedData{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TrustedDataDataDAABlock is an appmessage representation of externalapi.TrustedDataDataDAABlock
|
|
||||||
type TrustedDataDataDAABlock struct {
|
|
||||||
Block *MsgBlock
|
|
||||||
GHOSTDAGData *BlockGHOSTDAGData
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockGHOSTDAGData is an appmessage representation of externalapi.BlockGHOSTDAGData
|
|
||||||
type BlockGHOSTDAGData struct {
|
|
||||||
BlueScore uint64
|
|
||||||
BlueWork *big.Int
|
|
||||||
SelectedParent *externalapi.DomainHash
|
|
||||||
MergeSetBlues []*externalapi.DomainHash
|
|
||||||
MergeSetReds []*externalapi.DomainHash
|
|
||||||
BluesAnticoneSizes []*BluesAnticoneSizes
|
|
||||||
}
|
|
||||||
|
|
||||||
// BluesAnticoneSizes is an appmessage representation of the BluesAnticoneSizes part of GHOSTDAG data.
|
|
||||||
type BluesAnticoneSizes struct {
|
|
||||||
BlueHash *externalapi.DomainHash
|
|
||||||
AnticoneSize externalapi.KType
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockGHOSTDAGDataHashPair is an appmessage representation of externalapi.BlockGHOSTDAGDataHashPair
|
|
||||||
type BlockGHOSTDAGDataHashPair struct {
|
|
||||||
Hash *externalapi.DomainHash
|
|
||||||
GHOSTDAGData *BlockGHOSTDAGData
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// MsgDoneBlocksWithTrustedData implements the Message interface and represents a kaspa
|
|
||||||
// DoneBlocksWithTrustedData message
|
|
||||||
//
|
|
||||||
// This message has no payload.
|
|
||||||
type MsgDoneBlocksWithTrustedData struct {
|
|
||||||
baseMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message. This is part
|
|
||||||
// of the Message interface implementation.
|
|
||||||
func (msg *MsgDoneBlocksWithTrustedData) Command() MessageCommand {
|
|
||||||
return CmdDoneBlocksWithTrustedData
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgDoneBlocksWithTrustedData returns a new kaspa DoneBlocksWithTrustedData message that conforms to the
|
|
||||||
// Message interface.
|
|
||||||
func NewMsgDoneBlocksWithTrustedData() *MsgDoneBlocksWithTrustedData {
|
|
||||||
return &MsgDoneBlocksWithTrustedData{}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// MsgRequestPruningPointAndItsAnticone represents a kaspa RequestPruningPointAndItsAnticone message
|
|
||||||
type MsgRequestPruningPointAndItsAnticone struct {
|
|
||||||
baseMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *MsgRequestPruningPointAndItsAnticone) Command() MessageCommand {
|
|
||||||
return CmdRequestPruningPointAndItsAnticone
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgRequestPruningPointAndItsAnticone returns a new MsgRequestPruningPointAndItsAnticone.
|
|
||||||
func NewMsgRequestPruningPointAndItsAnticone() *MsgRequestPruningPointAndItsAnticone {
|
|
||||||
return &MsgRequestPruningPointAndItsAnticone{}
|
|
||||||
}
|
|
||||||
65
app/appmessage/p2p_msgibdblock_test.go
Normal file
65
app/appmessage/p2p_msgibdblock_test.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// Copyright (c) 2013-2016 The btcsuite developers
|
||||||
|
// Use of this source code is governed by an ISC
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package appmessage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestIBDBlock tests the MsgIBDBlock API.
|
||||||
|
func TestIBDBlock(t *testing.T) {
|
||||||
|
pver := ProtocolVersion
|
||||||
|
|
||||||
|
// Block 1 header.
|
||||||
|
parentHashes := blockOne.Header.ParentHashes
|
||||||
|
hashMerkleRoot := blockOne.Header.HashMerkleRoot
|
||||||
|
acceptedIDMerkleRoot := blockOne.Header.AcceptedIDMerkleRoot
|
||||||
|
utxoCommitment := blockOne.Header.UTXOCommitment
|
||||||
|
bits := blockOne.Header.Bits
|
||||||
|
nonce := blockOne.Header.Nonce
|
||||||
|
bh := NewBlockHeader(1, parentHashes, hashMerkleRoot, acceptedIDMerkleRoot, utxoCommitment, bits, nonce)
|
||||||
|
|
||||||
|
// Ensure the command is expected value.
|
||||||
|
wantCmd := MessageCommand(15)
|
||||||
|
msg := NewMsgIBDBlock(NewMsgBlock(bh))
|
||||||
|
if cmd := msg.Command(); cmd != wantCmd {
|
||||||
|
t.Errorf("NewMsgIBDBlock: wrong command - got %v want %v",
|
||||||
|
cmd, wantCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure max payload is expected value for latest protocol version.
|
||||||
|
wantPayload := uint32(1024 * 1024 * 32)
|
||||||
|
maxPayload := msg.MaxPayloadLength(pver)
|
||||||
|
if maxPayload != wantPayload {
|
||||||
|
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
||||||
|
"protocol version %d - got %v, want %v", pver,
|
||||||
|
maxPayload, wantPayload)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure we get the same block header data back out.
|
||||||
|
if !reflect.DeepEqual(&msg.Header, bh) {
|
||||||
|
t.Errorf("NewMsgIBDBlock: wrong block header - got %v, want %v",
|
||||||
|
spew.Sdump(&msg.Header), spew.Sdump(bh))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure transactions are added properly.
|
||||||
|
tx := blockOne.Transactions[0].Copy()
|
||||||
|
msg.AddTransaction(tx)
|
||||||
|
if !reflect.DeepEqual(msg.Transactions, blockOne.Transactions) {
|
||||||
|
t.Errorf("AddTransaction: wrong transactions - got %v, want %v",
|
||||||
|
spew.Sdump(msg.Transactions),
|
||||||
|
spew.Sdump(blockOne.Transactions))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure transactions are properly cleared.
|
||||||
|
msg.ClearTransactions()
|
||||||
|
if len(msg.Transactions) != 0 {
|
||||||
|
t.Errorf("ClearTransactions: wrong transactions - got %v, want %v",
|
||||||
|
len(msg.Transactions), 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/appmessage/p2p_msgpruningpointhash.go
Normal file
23
app/appmessage/p2p_msgpruningpointhash.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package appmessage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MsgPruningPointHashMessage represents a kaspa PruningPointHash message
|
||||||
|
type MsgPruningPointHashMessage struct {
|
||||||
|
baseMessage
|
||||||
|
Hash *externalapi.DomainHash
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command returns the protocol command string for the message
|
||||||
|
func (msg *MsgPruningPointHashMessage) Command() MessageCommand {
|
||||||
|
return CmdPruningPointHash
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPruningPointHashMessage returns a new kaspa PruningPointHash message
|
||||||
|
func NewPruningPointHashMessage(hash *externalapi.DomainHash) *MsgPruningPointHashMessage {
|
||||||
|
return &MsgPruningPointHashMessage{
|
||||||
|
Hash: hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// MsgPruningPointProof represents a kaspa PruningPointProof message
|
|
||||||
type MsgPruningPointProof struct {
|
|
||||||
baseMessage
|
|
||||||
|
|
||||||
Headers [][]*MsgBlockHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *MsgPruningPointProof) Command() MessageCommand {
|
|
||||||
return CmdPruningPointProof
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgPruningPointProof returns a new MsgPruningPointProof.
|
|
||||||
func NewMsgPruningPointProof(headers [][]*MsgBlockHeader) *MsgPruningPointProof {
|
|
||||||
return &MsgPruningPointProof{
|
|
||||||
Headers: headers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// MsgPruningPoints represents a kaspa PruningPoints message
|
|
||||||
type MsgPruningPoints struct {
|
|
||||||
baseMessage
|
|
||||||
|
|
||||||
Headers []*MsgBlockHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *MsgPruningPoints) Command() MessageCommand {
|
|
||||||
return CmdPruningPoints
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgPruningPoints returns a new MsgPruningPoints.
|
|
||||||
func NewMsgPruningPoints(headers []*MsgBlockHeader) *MsgPruningPoints {
|
|
||||||
return &MsgPruningPoints{
|
|
||||||
Headers: headers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,6 +31,6 @@ type OutpointAndUTXOEntryPair struct {
|
|||||||
type UTXOEntry struct {
|
type UTXOEntry struct {
|
||||||
Amount uint64
|
Amount uint64
|
||||||
ScriptPublicKey *externalapi.ScriptPublicKey
|
ScriptPublicKey *externalapi.ScriptPublicKey
|
||||||
BlockDAAScore uint64
|
BlockBlueScore uint64
|
||||||
IsCoinbase bool
|
IsCoinbase bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
// The locator is returned via a locator message (MsgBlockLocator).
|
// The locator is returned via a locator message (MsgBlockLocator).
|
||||||
type MsgRequestBlockLocator struct {
|
type MsgRequestBlockLocator struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
|
LowHash *externalapi.DomainHash
|
||||||
HighHash *externalapi.DomainHash
|
HighHash *externalapi.DomainHash
|
||||||
Limit uint32
|
Limit uint32
|
||||||
}
|
}
|
||||||
@@ -23,8 +24,9 @@ func (msg *MsgRequestBlockLocator) Command() MessageCommand {
|
|||||||
// NewMsgRequestBlockLocator returns a new RequestBlockLocator message that conforms to the
|
// NewMsgRequestBlockLocator returns a new RequestBlockLocator message that conforms to the
|
||||||
// Message interface using the passed parameters and defaults for the remaining
|
// Message interface using the passed parameters and defaults for the remaining
|
||||||
// fields.
|
// fields.
|
||||||
func NewMsgRequestBlockLocator(highHash *externalapi.DomainHash, limit uint32) *MsgRequestBlockLocator {
|
func NewMsgRequestBlockLocator(lowHash, highHash *externalapi.DomainHash, limit uint32) *MsgRequestBlockLocator {
|
||||||
return &MsgRequestBlockLocator{
|
return &MsgRequestBlockLocator{
|
||||||
|
LowHash: lowHash,
|
||||||
HighHash: highHash,
|
HighHash: highHash,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestRequestBlockLocator(t *testing.T) {
|
|||||||
|
|
||||||
// Ensure the command is expected value.
|
// Ensure the command is expected value.
|
||||||
wantCmd := MessageCommand(9)
|
wantCmd := MessageCommand(9)
|
||||||
msg := NewMsgRequestBlockLocator(highHash, 0)
|
msg := NewMsgRequestBlockLocator(highHash, &externalapi.DomainHash{}, 0)
|
||||||
if cmd := msg.Command(); cmd != wantCmd {
|
if cmd := msg.Command(); cmd != wantCmd {
|
||||||
t.Errorf("NewMsgRequestBlockLocator: wrong command - got %v want %v",
|
t.Errorf("NewMsgRequestBlockLocator: wrong command - got %v want %v",
|
||||||
cmd, wantCmd)
|
cmd, wantCmd)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestRequstIBDBlocks tests the MsgRequestIBDBlocks API.
|
// TestRequstIBDBlocks tests the MsgRequestHeaders API.
|
||||||
func TestRequstIBDBlocks(t *testing.T) {
|
func TestRequstIBDBlocks(t *testing.T) {
|
||||||
hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
|
hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
|
||||||
lowHash, err := externalapi.NewDomainHashFromString(hashStr)
|
lowHash, err := externalapi.NewDomainHashFromString(hashStr)
|
||||||
@@ -27,14 +27,14 @@ func TestRequstIBDBlocks(t *testing.T) {
|
|||||||
// Ensure we get the same data back out.
|
// Ensure we get the same data back out.
|
||||||
msg := NewMsgRequstHeaders(lowHash, highHash)
|
msg := NewMsgRequstHeaders(lowHash, highHash)
|
||||||
if !msg.HighHash.Equal(highHash) {
|
if !msg.HighHash.Equal(highHash) {
|
||||||
t.Errorf("NewMsgRequstIBDBlocks: wrong high hash - got %v, want %v",
|
t.Errorf("NewMsgRequstHeaders: wrong high hash - got %v, want %v",
|
||||||
msg.HighHash, highHash)
|
msg.HighHash, highHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the command is expected value.
|
// Ensure the command is expected value.
|
||||||
wantCmd := MessageCommand(4)
|
wantCmd := MessageCommand(4)
|
||||||
if cmd := msg.Command(); cmd != wantCmd {
|
if cmd := msg.Command(); cmd != wantCmd {
|
||||||
t.Errorf("NewMsgRequstIBDBlocks: wrong command - got %v want %v",
|
t.Errorf("NewMsgRequstHeaders: wrong command - got %v want %v",
|
||||||
cmd, wantCmd)
|
cmd, wantCmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// MsgRequestPruningPointProof represents a kaspa RequestPruningPointProof message
|
|
||||||
type MsgRequestPruningPointProof struct {
|
|
||||||
baseMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *MsgRequestPruningPointProof) Command() MessageCommand {
|
|
||||||
return CmdRequestPruningPointProof
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgRequestPruningPointProof returns a new MsgRequestPruningPointProof.
|
|
||||||
func NewMsgRequestPruningPointProof() *MsgRequestPruningPointProof {
|
|
||||||
return &MsgRequestPruningPointProof{}
|
|
||||||
}
|
|
||||||
@@ -4,20 +4,20 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MsgRequestPruningPointUTXOSet represents a kaspa RequestPruningPointUTXOSet message
|
// MsgRequestPruningPointUTXOSetAndBlock represents a kaspa RequestPruningPointUTXOSetAndBlock message
|
||||||
type MsgRequestPruningPointUTXOSet struct {
|
type MsgRequestPruningPointUTXOSetAndBlock struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
PruningPointHash *externalapi.DomainHash
|
PruningPointHash *externalapi.DomainHash
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
func (msg *MsgRequestPruningPointUTXOSet) Command() MessageCommand {
|
func (msg *MsgRequestPruningPointUTXOSetAndBlock) Command() MessageCommand {
|
||||||
return CmdRequestPruningPointUTXOSet
|
return CmdRequestPruningPointUTXOSetAndBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgRequestPruningPointUTXOSet returns a new MsgRequestPruningPointUTXOSet
|
// NewMsgRequestPruningPointUTXOSetAndBlock returns a new MsgRequestPruningPointUTXOSetAndBlock
|
||||||
func NewMsgRequestPruningPointUTXOSet(pruningPointHash *externalapi.DomainHash) *MsgRequestPruningPointUTXOSet {
|
func NewMsgRequestPruningPointUTXOSetAndBlock(pruningPointHash *externalapi.DomainHash) *MsgRequestPruningPointUTXOSetAndBlock {
|
||||||
return &MsgRequestPruningPointUTXOSet{
|
return &MsgRequestPruningPointUTXOSetAndBlock{
|
||||||
PruningPointHash: pruningPointHash,
|
PruningPointHash: pruningPointHash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package appmessage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
@@ -90,18 +91,16 @@ type TxIn struct {
|
|||||||
PreviousOutpoint Outpoint
|
PreviousOutpoint Outpoint
|
||||||
SignatureScript []byte
|
SignatureScript []byte
|
||||||
Sequence uint64
|
Sequence uint64
|
||||||
SigOpCount byte
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTxIn returns a new kaspa transaction input with the provided
|
// NewTxIn returns a new kaspa transaction input with the provided
|
||||||
// previous outpoint point and signature script with a default sequence of
|
// previous outpoint point and signature script with a default sequence of
|
||||||
// MaxTxInSequenceNum.
|
// MaxTxInSequenceNum.
|
||||||
func NewTxIn(prevOut *Outpoint, signatureScript []byte, sequence uint64, sigOpCount byte) *TxIn {
|
func NewTxIn(prevOut *Outpoint, signatureScript []byte, sequence uint64) *TxIn {
|
||||||
return &TxIn{
|
return &TxIn{
|
||||||
PreviousOutpoint: *prevOut,
|
PreviousOutpoint: *prevOut,
|
||||||
SignatureScript: signatureScript,
|
SignatureScript: signatureScript,
|
||||||
Sequence: sequence,
|
Sequence: sequence,
|
||||||
SigOpCount: sigOpCount,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +133,7 @@ type MsgTx struct {
|
|||||||
LockTime uint64
|
LockTime uint64
|
||||||
SubnetworkID externalapi.DomainSubnetworkID
|
SubnetworkID externalapi.DomainSubnetworkID
|
||||||
Gas uint64
|
Gas uint64
|
||||||
|
PayloadHash externalapi.DomainHash
|
||||||
Payload []byte
|
Payload []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +179,7 @@ func (msg *MsgTx) Copy() *MsgTx {
|
|||||||
LockTime: msg.LockTime,
|
LockTime: msg.LockTime,
|
||||||
SubnetworkID: msg.SubnetworkID,
|
SubnetworkID: msg.SubnetworkID,
|
||||||
Gas: msg.Gas,
|
Gas: msg.Gas,
|
||||||
|
PayloadHash: msg.PayloadHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Payload != nil {
|
if msg.Payload != nil {
|
||||||
@@ -208,7 +209,6 @@ func (msg *MsgTx) Copy() *MsgTx {
|
|||||||
PreviousOutpoint: newOutpoint,
|
PreviousOutpoint: newOutpoint,
|
||||||
SignatureScript: newScript,
|
SignatureScript: newScript,
|
||||||
Sequence: oldTxIn.Sequence,
|
Sequence: oldTxIn.Sequence,
|
||||||
SigOpCount: oldTxIn.SigOpCount,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, append this fully copied txin.
|
// Finally, append this fully copied txin.
|
||||||
@@ -280,12 +280,18 @@ func newMsgTx(version uint16, txIn []*TxIn, txOut []*TxOut, subnetworkID *extern
|
|||||||
txOut = make([]*TxOut, 0, defaultTxInOutAlloc)
|
txOut = make([]*TxOut, 0, defaultTxInOutAlloc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var payloadHash externalapi.DomainHash
|
||||||
|
if *subnetworkID != subnetworks.SubnetworkIDNative {
|
||||||
|
payloadHash = *hashes.PayloadHash(payload)
|
||||||
|
}
|
||||||
|
|
||||||
return &MsgTx{
|
return &MsgTx{
|
||||||
Version: version,
|
Version: version,
|
||||||
TxIn: txIn,
|
TxIn: txIn,
|
||||||
TxOut: txOut,
|
TxOut: txOut,
|
||||||
SubnetworkID: *subnetworkID,
|
SubnetworkID: *subnetworkID,
|
||||||
Gas: gas,
|
Gas: gas,
|
||||||
|
PayloadHash: payloadHash,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
LockTime: lockTime,
|
LockTime: lockTime,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func TestTx(t *testing.T) {
|
|||||||
|
|
||||||
// Ensure we get the same transaction input back out.
|
// Ensure we get the same transaction input back out.
|
||||||
sigScript := []byte{0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62}
|
sigScript := []byte{0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62}
|
||||||
txIn := NewTxIn(prevOut, sigScript, constants.MaxTxInSequenceNum, 1)
|
txIn := NewTxIn(prevOut, sigScript, constants.MaxTxInSequenceNum)
|
||||||
if !reflect.DeepEqual(&txIn.PreviousOutpoint, prevOut) {
|
if !reflect.DeepEqual(&txIn.PreviousOutpoint, prevOut) {
|
||||||
t.Errorf("NewTxIn: wrong prev outpoint - got %v, want %v",
|
t.Errorf("NewTxIn: wrong prev outpoint - got %v, want %v",
|
||||||
spew.Sprint(&txIn.PreviousOutpoint),
|
spew.Sprint(&txIn.PreviousOutpoint),
|
||||||
@@ -133,8 +133,8 @@ func TestTx(t *testing.T) {
|
|||||||
|
|
||||||
// TestTxHash tests the ability to generate the hash of a transaction accurately.
|
// TestTxHash tests the ability to generate the hash of a transaction accurately.
|
||||||
func TestTxHashAndID(t *testing.T) {
|
func TestTxHashAndID(t *testing.T) {
|
||||||
txHash1Str := "93663e597f6c968d32d229002f76408edf30d6a0151ff679fc729812d8cb2acc"
|
txHash1Str := "4bee9ee495bd93a755de428376bd582a2bb6ec37c041753b711c0606d5745c13"
|
||||||
txID1Str := "24079c6d2bdf602fc389cc307349054937744a9c8dc0f07c023e6af0e949a4e7"
|
txID1Str := "f868bd20e816256b80eac976821be4589d24d21141bd1cec6e8005d0c16c6881"
|
||||||
wantTxID1, err := transactionid.FromString(txID1Str)
|
wantTxID1, err := transactionid.FromString(txID1Str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("NewTxIDFromStr: %v", err)
|
t.Fatalf("NewTxIDFromStr: %v", err)
|
||||||
@@ -185,14 +185,14 @@ func TestTxHashAndID(t *testing.T) {
|
|||||||
spew.Sprint(tx1ID), spew.Sprint(wantTxID1))
|
spew.Sprint(tx1ID), spew.Sprint(wantTxID1))
|
||||||
}
|
}
|
||||||
|
|
||||||
hash2Str := "8dafd1bec24527d8e3b443ceb0a3b92fffc0d60026317f890b2faf5e9afc177a"
|
hash2Str := "cb1bdb4a83d4885535fb3cceb5c96597b7df903db83f0ffcd779d703affd8efd"
|
||||||
wantHash2, err := externalapi.NewDomainHashFromString(hash2Str)
|
wantHash2, err := externalapi.NewDomainHashFromString(hash2Str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("NewTxIDFromStr: %v", err)
|
t.Errorf("NewTxIDFromStr: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id2Str := "89ffb49474637502d9059af38b8a95fc2f0d3baef5c801d7a9b9c8830671b711"
|
id2Str := "ca080073d4ddf5b84443a0964af633f3c70a5b290fd3bc35a7e6f93fd33f9330"
|
||||||
wantID2, err := transactionid.FromString(id2Str)
|
wantID2, err := transactionid.FromString(id2Str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("NewTxIDFromStr: %v", err)
|
t.Errorf("NewTxIDFromStr: %v", err)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestVersion(t *testing.T) {
|
|||||||
|
|
||||||
// Create version message data.
|
// Create version message data.
|
||||||
tcpAddrMe := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 16111}
|
tcpAddrMe := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 16111}
|
||||||
me := NewNetAddress(tcpAddrMe)
|
me := NewNetAddress(tcpAddrMe, SFNodeNetwork)
|
||||||
generatedID, err := id.GenerateID()
|
generatedID, err := id.GenerateID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("id.GenerateID: %s", err)
|
t.Fatalf("id.GenerateID: %s", err)
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ type NetAddress struct {
|
|||||||
// Last time the address was seen.
|
// Last time the address was seen.
|
||||||
Timestamp mstime.Time
|
Timestamp mstime.Time
|
||||||
|
|
||||||
|
// Bitfield which identifies the services supported by the address.
|
||||||
|
Services ServiceFlag
|
||||||
|
|
||||||
// IP address of the peer.
|
// IP address of the peer.
|
||||||
IP net.IP
|
IP net.IP
|
||||||
|
|
||||||
@@ -23,6 +26,17 @@ type NetAddress struct {
|
|||||||
Port uint16
|
Port uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasService returns whether the specified service is supported by the address.
|
||||||
|
func (na *NetAddress) HasService(service ServiceFlag) bool {
|
||||||
|
return na.Services&service == service
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddService adds service as a supported service by the peer generating the
|
||||||
|
// message.
|
||||||
|
func (na *NetAddress) AddService(service ServiceFlag) {
|
||||||
|
na.Services |= service
|
||||||
|
}
|
||||||
|
|
||||||
// TCPAddress converts the NetAddress to *net.TCPAddr
|
// TCPAddress converts the NetAddress to *net.TCPAddr
|
||||||
func (na *NetAddress) TCPAddress() *net.TCPAddr {
|
func (na *NetAddress) TCPAddress() *net.TCPAddr {
|
||||||
return &net.TCPAddr{
|
return &net.TCPAddr{
|
||||||
@@ -33,19 +47,20 @@ func (na *NetAddress) TCPAddress() *net.TCPAddr {
|
|||||||
|
|
||||||
// NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and
|
// NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and
|
||||||
// supported services with defaults for the remaining fields.
|
// supported services with defaults for the remaining fields.
|
||||||
func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress {
|
func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress {
|
||||||
return NewNetAddressTimestamp(mstime.Now(), ip, port)
|
return NewNetAddressTimestamp(mstime.Now(), services, ip, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNetAddressTimestamp returns a new NetAddress using the provided
|
// NewNetAddressTimestamp returns a new NetAddress using the provided
|
||||||
// timestamp, IP, port, and supported services. The timestamp is rounded to
|
// timestamp, IP, port, and supported services. The timestamp is rounded to
|
||||||
// single millisecond precision.
|
// single millisecond precision.
|
||||||
func NewNetAddressTimestamp(
|
func NewNetAddressTimestamp(
|
||||||
timestamp mstime.Time, ip net.IP, port uint16) *NetAddress {
|
timestamp mstime.Time, services ServiceFlag, ip net.IP, port uint16) *NetAddress {
|
||||||
// Limit the timestamp to one millisecond precision since the protocol
|
// Limit the timestamp to one millisecond precision since the protocol
|
||||||
// doesn't support better.
|
// doesn't support better.
|
||||||
na := NetAddress{
|
na := NetAddress{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
|
Services: services,
|
||||||
IP: ip,
|
IP: ip,
|
||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
@@ -54,6 +69,6 @@ func NewNetAddressTimestamp(
|
|||||||
|
|
||||||
// NewNetAddress returns a new NetAddress using the provided TCP address and
|
// NewNetAddress returns a new NetAddress using the provided TCP address and
|
||||||
// supported services with defaults for the remaining fields.
|
// supported services with defaults for the remaining fields.
|
||||||
func NewNetAddress(addr *net.TCPAddr) *NetAddress {
|
func NewNetAddress(addr *net.TCPAddr, services ServiceFlag) *NetAddress {
|
||||||
return NewNetAddressIPPort(addr.IP, uint16(addr.Port))
|
return NewNetAddressIPPort(addr.IP, uint16(addr.Port), services)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func TestNetAddress(t *testing.T) {
|
|||||||
port := 16111
|
port := 16111
|
||||||
|
|
||||||
// Test NewNetAddress.
|
// Test NewNetAddress.
|
||||||
na := NewNetAddress(&net.TCPAddr{IP: ip, Port: port})
|
na := NewNetAddress(&net.TCPAddr{IP: ip, Port: port}, 0)
|
||||||
|
|
||||||
// Ensure we get the same ip, port, and services back out.
|
// Ensure we get the same ip, port, and services back out.
|
||||||
if !na.IP.Equal(ip) {
|
if !na.IP.Equal(ip) {
|
||||||
@@ -25,4 +25,21 @@ func TestNetAddress(t *testing.T) {
|
|||||||
t.Errorf("NetNetAddress: wrong port - got %v, want %v", na.Port,
|
t.Errorf("NetNetAddress: wrong port - got %v, want %v", na.Port,
|
||||||
port)
|
port)
|
||||||
}
|
}
|
||||||
|
if na.Services != 0 {
|
||||||
|
t.Errorf("NetNetAddress: wrong services - got %v, want %v",
|
||||||
|
na.Services, 0)
|
||||||
|
}
|
||||||
|
if na.HasService(SFNodeNetwork) {
|
||||||
|
t.Errorf("HasService: SFNodeNetwork service is set")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure adding the full service node flag works.
|
||||||
|
na.AddService(SFNodeNetwork)
|
||||||
|
if na.Services != SFNodeNetwork {
|
||||||
|
t.Errorf("AddService: wrong services - got %v, want %v",
|
||||||
|
na.Services, SFNodeNetwork)
|
||||||
|
}
|
||||||
|
if !na.HasService(SFNodeNetwork) {
|
||||||
|
t.Errorf("HasService: SFNodeNetwork service not set")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
app/appmessage/p2p_requestpruningpointhash.go
Normal file
16
app/appmessage/p2p_requestpruningpointhash.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package appmessage
|
||||||
|
|
||||||
|
// MsgRequestPruningPointHashMessage represents a kaspa RequestPruningPointHashMessage message
|
||||||
|
type MsgRequestPruningPointHashMessage struct {
|
||||||
|
baseMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command returns the protocol command string for the message
|
||||||
|
func (msg *MsgRequestPruningPointHashMessage) Command() MessageCommand {
|
||||||
|
return CmdRequestPruningPointHash
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMsgRequestPruningPointHashMessage returns a new kaspa RequestPruningPointHash message
|
||||||
|
func NewMsgRequestPruningPointHashMessage() *MsgRequestPruningPointHashMessage {
|
||||||
|
return &MsgRequestPruningPointHashMessage{}
|
||||||
|
}
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// EstimateNetworkHashesPerSecondRequestMessage is an appmessage corresponding to
|
|
||||||
// its respective RPC message
|
|
||||||
type EstimateNetworkHashesPerSecondRequestMessage struct {
|
|
||||||
baseMessage
|
|
||||||
StartHash string
|
|
||||||
WindowSize uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *EstimateNetworkHashesPerSecondRequestMessage) Command() MessageCommand {
|
|
||||||
return CmdEstimateNetworkHashesPerSecondRequestMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewEstimateNetworkHashesPerSecondRequestMessage returns a instance of the message
|
|
||||||
func NewEstimateNetworkHashesPerSecondRequestMessage(startHash string, windowSize uint32) *EstimateNetworkHashesPerSecondRequestMessage {
|
|
||||||
return &EstimateNetworkHashesPerSecondRequestMessage{
|
|
||||||
StartHash: startHash,
|
|
||||||
WindowSize: windowSize,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EstimateNetworkHashesPerSecondResponseMessage is an appmessage corresponding to
|
|
||||||
// its respective RPC message
|
|
||||||
type EstimateNetworkHashesPerSecondResponseMessage struct {
|
|
||||||
baseMessage
|
|
||||||
NetworkHashesPerSecond uint64
|
|
||||||
|
|
||||||
Error *RPCError
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *EstimateNetworkHashesPerSecondResponseMessage) Command() MessageCommand {
|
|
||||||
return CmdEstimateNetworkHashesPerSecondResponseMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewEstimateNetworkHashesPerSecondResponseMessage returns a instance of the message
|
|
||||||
func NewEstimateNetworkHashesPerSecondResponseMessage(networkHashesPerSecond uint64) *EstimateNetworkHashesPerSecondResponseMessage {
|
|
||||||
return &EstimateNetworkHashesPerSecondResponseMessage{
|
|
||||||
NetworkHashesPerSecond: networkHashesPerSecond,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ package appmessage
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type GetBlockRequestMessage struct {
|
type GetBlockRequestMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Hash string
|
Hash string
|
||||||
IncludeTransactions bool
|
IncludeTransactionVerboseData bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -14,10 +14,10 @@ func (msg *GetBlockRequestMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetBlockRequestMessage returns a instance of the message
|
// NewGetBlockRequestMessage returns a instance of the message
|
||||||
func NewGetBlockRequestMessage(hash string, includeTransactions bool) *GetBlockRequestMessage {
|
func NewGetBlockRequestMessage(hash string, includeTransactionVerboseData bool) *GetBlockRequestMessage {
|
||||||
return &GetBlockRequestMessage{
|
return &GetBlockRequestMessage{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
IncludeTransactions: includeTransactions,
|
IncludeTransactionVerboseData: includeTransactionVerboseData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ func NewGetBlockRequestMessage(hash string, includeTransactions bool) *GetBlockR
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type GetBlockResponseMessage struct {
|
type GetBlockResponseMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Block *RPCBlock
|
BlockVerboseData *BlockVerboseData
|
||||||
|
|
||||||
Error *RPCError
|
Error *RPCError
|
||||||
}
|
}
|
||||||
@@ -39,3 +39,71 @@ func (msg *GetBlockResponseMessage) Command() MessageCommand {
|
|||||||
func NewGetBlockResponseMessage() *GetBlockResponseMessage {
|
func NewGetBlockResponseMessage() *GetBlockResponseMessage {
|
||||||
return &GetBlockResponseMessage{}
|
return &GetBlockResponseMessage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlockVerboseData holds verbose data about a block
|
||||||
|
type BlockVerboseData struct {
|
||||||
|
Hash string
|
||||||
|
Version uint16
|
||||||
|
VersionHex string
|
||||||
|
HashMerkleRoot string
|
||||||
|
AcceptedIDMerkleRoot string
|
||||||
|
UTXOCommitment string
|
||||||
|
TxIDs []string
|
||||||
|
TransactionVerboseData []*TransactionVerboseData
|
||||||
|
Time int64
|
||||||
|
Nonce uint64
|
||||||
|
Bits string
|
||||||
|
Difficulty float64
|
||||||
|
ParentHashes []string
|
||||||
|
ChildrenHashes []string
|
||||||
|
SelectedParentHash string
|
||||||
|
BlueScore uint64
|
||||||
|
IsHeaderOnly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransactionVerboseData holds verbose data about a transaction
|
||||||
|
type TransactionVerboseData struct {
|
||||||
|
TxID string
|
||||||
|
Hash string
|
||||||
|
Size uint64
|
||||||
|
Version uint16
|
||||||
|
LockTime uint64
|
||||||
|
SubnetworkID string
|
||||||
|
Gas uint64
|
||||||
|
PayloadHash string
|
||||||
|
Payload string
|
||||||
|
TransactionVerboseInputs []*TransactionVerboseInput
|
||||||
|
TransactionVerboseOutputs []*TransactionVerboseOutput
|
||||||
|
BlockHash string
|
||||||
|
Time uint64
|
||||||
|
BlockTime uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransactionVerboseInput holds data about a transaction input
|
||||||
|
type TransactionVerboseInput struct {
|
||||||
|
TxID string
|
||||||
|
OutputIndex uint32
|
||||||
|
ScriptSig *ScriptSig
|
||||||
|
Sequence uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScriptSig holds data about a script signature
|
||||||
|
type ScriptSig struct {
|
||||||
|
Asm string
|
||||||
|
Hex string
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransactionVerboseOutput holds data about a transaction output
|
||||||
|
type TransactionVerboseOutput struct {
|
||||||
|
Value uint64
|
||||||
|
Index uint32
|
||||||
|
ScriptPubKey *ScriptPubKeyResult
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScriptPubKeyResult holds data about a script public key
|
||||||
|
type ScriptPubKeyResult struct {
|
||||||
|
Hex string
|
||||||
|
Type string
|
||||||
|
Address string
|
||||||
|
Version uint16
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ type GetBlockDAGInfoResponseMessage struct {
|
|||||||
Difficulty float64
|
Difficulty float64
|
||||||
PastMedianTime int64
|
PastMedianTime int64
|
||||||
PruningPointHash string
|
PruningPointHash string
|
||||||
VirtualDAAScore uint64
|
|
||||||
|
|
||||||
Error *RPCError
|
Error *RPCError
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func NewGetBlockTemplateRequestMessage(payAddress string) *GetBlockTemplateReque
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type GetBlockTemplateResponseMessage struct {
|
type GetBlockTemplateResponseMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Block *RPCBlock
|
MsgBlock *MsgBlock
|
||||||
IsSynced bool
|
IsSynced bool
|
||||||
|
|
||||||
Error *RPCError
|
Error *RPCError
|
||||||
@@ -35,9 +35,9 @@ func (msg *GetBlockTemplateResponseMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetBlockTemplateResponseMessage returns a instance of the message
|
// NewGetBlockTemplateResponseMessage returns a instance of the message
|
||||||
func NewGetBlockTemplateResponseMessage(block *RPCBlock, isSynced bool) *GetBlockTemplateResponseMessage {
|
func NewGetBlockTemplateResponseMessage(msgBlock *MsgBlock, isSynced bool) *GetBlockTemplateResponseMessage {
|
||||||
return &GetBlockTemplateResponseMessage{
|
return &GetBlockTemplateResponseMessage{
|
||||||
Block: block,
|
MsgBlock: msgBlock,
|
||||||
IsSynced: isSynced,
|
IsSynced: isSynced,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ package appmessage
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type GetBlocksRequestMessage struct {
|
type GetBlocksRequestMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
LowHash string
|
LowHash string
|
||||||
IncludeBlocks bool
|
IncludeBlockVerboseData bool
|
||||||
IncludeTransactions bool
|
IncludeTransactionVerboseData bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -15,12 +15,12 @@ func (msg *GetBlocksRequestMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetBlocksRequestMessage returns a instance of the message
|
// NewGetBlocksRequestMessage returns a instance of the message
|
||||||
func NewGetBlocksRequestMessage(lowHash string, includeBlocks bool,
|
func NewGetBlocksRequestMessage(lowHash string, includeBlockVerboseData bool,
|
||||||
includeTransactions bool) *GetBlocksRequestMessage {
|
includeTransactionVerboseData bool) *GetBlocksRequestMessage {
|
||||||
return &GetBlocksRequestMessage{
|
return &GetBlocksRequestMessage{
|
||||||
LowHash: lowHash,
|
LowHash: lowHash,
|
||||||
IncludeBlocks: includeBlocks,
|
IncludeBlockVerboseData: includeBlockVerboseData,
|
||||||
IncludeTransactions: includeTransactions,
|
IncludeTransactionVerboseData: includeTransactionVerboseData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,8 +28,8 @@ func NewGetBlocksRequestMessage(lowHash string, includeBlocks bool,
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type GetBlocksResponseMessage struct {
|
type GetBlocksResponseMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
BlockHashes []string
|
BlockHashes []string
|
||||||
Blocks []*RPCBlock
|
BlockVerboseData []*BlockVerboseData
|
||||||
|
|
||||||
Error *RPCError
|
Error *RPCError
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,11 @@ func (msg *GetBlocksResponseMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetBlocksResponseMessage returns a instance of the message
|
// NewGetBlocksResponseMessage returns a instance of the message
|
||||||
func NewGetBlocksResponseMessage() *GetBlocksResponseMessage {
|
func NewGetBlocksResponseMessage(blockHashes []string, blockHexes []string,
|
||||||
return &GetBlocksResponseMessage{}
|
blockVerboseData []*BlockVerboseData) *GetBlocksResponseMessage {
|
||||||
|
|
||||||
|
return &GetBlocksResponseMessage{
|
||||||
|
BlockHashes: blockHashes,
|
||||||
|
BlockVerboseData: blockVerboseData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ func (msg *GetInfoRequestMessage) Command() MessageCommand {
|
|||||||
return CmdGetInfoRequestMessage
|
return CmdGetInfoRequestMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGetInfoRequestMessage returns a instance of the message
|
// NewGeInfoRequestMessage returns a instance of the message
|
||||||
func NewGetInfoRequestMessage() *GetInfoRequestMessage {
|
func NewGeInfoRequestMessage() *GetInfoRequestMessage {
|
||||||
return &GetInfoRequestMessage{}
|
return &GetInfoRequestMessage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,9 +20,7 @@ func NewGetInfoRequestMessage() *GetInfoRequestMessage {
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type GetInfoResponseMessage struct {
|
type GetInfoResponseMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
P2PID string
|
P2PID string
|
||||||
MempoolSize uint64
|
|
||||||
ServerVersion string
|
|
||||||
|
|
||||||
Error *RPCError
|
Error *RPCError
|
||||||
}
|
}
|
||||||
@@ -33,10 +31,8 @@ func (msg *GetInfoResponseMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetInfoResponseMessage returns a instance of the message
|
// NewGetInfoResponseMessage returns a instance of the message
|
||||||
func NewGetInfoResponseMessage(p2pID string, mempoolSize uint64, serverVersion string) *GetInfoResponseMessage {
|
func NewGetInfoResponseMessage(p2pID string) *GetInfoResponseMessage {
|
||||||
return &GetInfoResponseMessage{
|
return &GetInfoResponseMessage{
|
||||||
P2PID: p2pID,
|
P2PID: p2pID,
|
||||||
MempoolSize: mempoolSize,
|
|
||||||
ServerVersion: serverVersion,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ type GetMempoolEntryResponseMessage struct {
|
|||||||
|
|
||||||
// MempoolEntry represents a transaction in the mempool.
|
// MempoolEntry represents a transaction in the mempool.
|
||||||
type MempoolEntry struct {
|
type MempoolEntry struct {
|
||||||
Fee uint64
|
Fee uint64
|
||||||
Transaction *RPCTransaction
|
TransactionVerboseData *TransactionVerboseData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -38,11 +38,11 @@ func (msg *GetMempoolEntryResponseMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetMempoolEntryResponseMessage returns a instance of the message
|
// NewGetMempoolEntryResponseMessage returns a instance of the message
|
||||||
func NewGetMempoolEntryResponseMessage(fee uint64, transaction *RPCTransaction) *GetMempoolEntryResponseMessage {
|
func NewGetMempoolEntryResponseMessage(fee uint64, transactionVerboseData *TransactionVerboseData) *GetMempoolEntryResponseMessage {
|
||||||
return &GetMempoolEntryResponseMessage{
|
return &GetMempoolEntryResponseMessage{
|
||||||
Entry: &MempoolEntry{
|
Entry: &MempoolEntry{
|
||||||
Fee: fee,
|
Fee: fee,
|
||||||
Transaction: transaction,
|
TransactionVerboseData: transactionVerboseData,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func NewGetVirtualSelectedParentChainFromBlockRequestMessage(startHash string) *
|
|||||||
type GetVirtualSelectedParentChainFromBlockResponseMessage struct {
|
type GetVirtualSelectedParentChainFromBlockResponseMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
RemovedChainBlockHashes []string
|
RemovedChainBlockHashes []string
|
||||||
AddedChainBlockHashes []string
|
AddedChainBlocks []*ChainBlock
|
||||||
|
|
||||||
Error *RPCError
|
Error *RPCError
|
||||||
}
|
}
|
||||||
@@ -35,11 +35,11 @@ func (msg *GetVirtualSelectedParentChainFromBlockResponseMessage) Command() Mess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGetVirtualSelectedParentChainFromBlockResponseMessage returns a instance of the message
|
// NewGetVirtualSelectedParentChainFromBlockResponseMessage returns a instance of the message
|
||||||
func NewGetVirtualSelectedParentChainFromBlockResponseMessage(removedChainBlockHashes,
|
func NewGetVirtualSelectedParentChainFromBlockResponseMessage(removedChainBlockHashes []string,
|
||||||
addedChainBlockHashes []string) *GetVirtualSelectedParentChainFromBlockResponseMessage {
|
addedChainBlocks []*ChainBlock) *GetVirtualSelectedParentChainFromBlockResponseMessage {
|
||||||
|
|
||||||
return &GetVirtualSelectedParentChainFromBlockResponseMessage{
|
return &GetVirtualSelectedParentChainFromBlockResponseMessage{
|
||||||
RemovedChainBlockHashes: removedChainBlockHashes,
|
RemovedChainBlockHashes: removedChainBlockHashes,
|
||||||
AddedChainBlockHashes: addedChainBlockHashes,
|
AddedChainBlocks: addedChainBlocks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ func NewNotifyBlockAddedResponseMessage() *NotifyBlockAddedResponseMessage {
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type BlockAddedNotificationMessage struct {
|
type BlockAddedNotificationMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Block *RPCBlock
|
Block *MsgBlock
|
||||||
|
BlockVerboseData *BlockVerboseData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -46,8 +47,9 @@ func (msg *BlockAddedNotificationMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockAddedNotificationMessage returns a instance of the message
|
// NewBlockAddedNotificationMessage returns a instance of the message
|
||||||
func NewBlockAddedNotificationMessage(block *RPCBlock) *BlockAddedNotificationMessage {
|
func NewBlockAddedNotificationMessage(block *MsgBlock, blockVerboseData *BlockVerboseData) *BlockAddedNotificationMessage {
|
||||||
return &BlockAddedNotificationMessage{
|
return &BlockAddedNotificationMessage{
|
||||||
Block: block,
|
Block: block,
|
||||||
|
BlockVerboseData: blockVerboseData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
package appmessage
|
|
||||||
|
|
||||||
// NotifyVirtualDaaScoreChangedRequestMessage is an appmessage corresponding to
|
|
||||||
// its respective RPC message
|
|
||||||
type NotifyVirtualDaaScoreChangedRequestMessage struct {
|
|
||||||
baseMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *NotifyVirtualDaaScoreChangedRequestMessage) Command() MessageCommand {
|
|
||||||
return CmdNotifyVirtualDaaScoreChangedRequestMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewNotifyVirtualDaaScoreChangedRequestMessage returns a instance of the message
|
|
||||||
func NewNotifyVirtualDaaScoreChangedRequestMessage() *NotifyVirtualDaaScoreChangedRequestMessage {
|
|
||||||
return &NotifyVirtualDaaScoreChangedRequestMessage{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotifyVirtualDaaScoreChangedResponseMessage is an appmessage corresponding to
|
|
||||||
// its respective RPC message
|
|
||||||
type NotifyVirtualDaaScoreChangedResponseMessage struct {
|
|
||||||
baseMessage
|
|
||||||
Error *RPCError
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *NotifyVirtualDaaScoreChangedResponseMessage) Command() MessageCommand {
|
|
||||||
return CmdNotifyVirtualDaaScoreChangedResponseMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewNotifyVirtualDaaScoreChangedResponseMessage returns a instance of the message
|
|
||||||
func NewNotifyVirtualDaaScoreChangedResponseMessage() *NotifyVirtualDaaScoreChangedResponseMessage {
|
|
||||||
return &NotifyVirtualDaaScoreChangedResponseMessage{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualDaaScoreChangedNotificationMessage is an appmessage corresponding to
|
|
||||||
// its respective RPC message
|
|
||||||
type VirtualDaaScoreChangedNotificationMessage struct {
|
|
||||||
baseMessage
|
|
||||||
VirtualDaaScore uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
|
||||||
func (msg *VirtualDaaScoreChangedNotificationMessage) Command() MessageCommand {
|
|
||||||
return CmdVirtualDaaScoreChangedNotificationMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewVirtualDaaScoreChangedNotificationMessage returns a instance of the message
|
|
||||||
func NewVirtualDaaScoreChangedNotificationMessage(
|
|
||||||
virtualDaaScore uint64) *VirtualDaaScoreChangedNotificationMessage {
|
|
||||||
|
|
||||||
return &VirtualDaaScoreChangedNotificationMessage{
|
|
||||||
VirtualDaaScore: virtualDaaScore,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,19 @@ func NewNotifyVirtualSelectedParentChainChangedResponseMessage() *NotifyVirtualS
|
|||||||
type VirtualSelectedParentChainChangedNotificationMessage struct {
|
type VirtualSelectedParentChainChangedNotificationMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
RemovedChainBlockHashes []string
|
RemovedChainBlockHashes []string
|
||||||
AddedChainBlockHashes []string
|
AddedChainBlocks []*ChainBlock
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChainBlock represents a DAG chain-block
|
||||||
|
type ChainBlock struct {
|
||||||
|
Hash string
|
||||||
|
AcceptedBlocks []*AcceptedBlock
|
||||||
|
}
|
||||||
|
|
||||||
|
// AcceptedBlock represents a block accepted into the DAG
|
||||||
|
type AcceptedBlock struct {
|
||||||
|
Hash string
|
||||||
|
AcceptedTransactionIDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -47,11 +59,11 @@ func (msg *VirtualSelectedParentChainChangedNotificationMessage) Command() Messa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewVirtualSelectedParentChainChangedNotificationMessage returns a instance of the message
|
// NewVirtualSelectedParentChainChangedNotificationMessage returns a instance of the message
|
||||||
func NewVirtualSelectedParentChainChangedNotificationMessage(removedChainBlockHashes,
|
func NewVirtualSelectedParentChainChangedNotificationMessage(removedChainBlockHashes []string,
|
||||||
addedChainBlocks []string) *VirtualSelectedParentChainChangedNotificationMessage {
|
addedChainBlocks []*ChainBlock) *VirtualSelectedParentChainChangedNotificationMessage {
|
||||||
|
|
||||||
return &VirtualSelectedParentChainChangedNotificationMessage{
|
return &VirtualSelectedParentChainChangedNotificationMessage{
|
||||||
RemovedChainBlockHashes: removedChainBlockHashes,
|
RemovedChainBlockHashes: removedChainBlockHashes,
|
||||||
AddedChainBlockHashes: addedChainBlocks,
|
AddedChainBlocks: addedChainBlocks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package appmessage
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type SubmitBlockRequestMessage struct {
|
type SubmitBlockRequestMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Block *RPCBlock
|
Block *MsgBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -13,7 +13,7 @@ func (msg *SubmitBlockRequestMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSubmitBlockRequestMessage returns a instance of the message
|
// NewSubmitBlockRequestMessage returns a instance of the message
|
||||||
func NewSubmitBlockRequestMessage(block *RPCBlock) *SubmitBlockRequestMessage {
|
func NewSubmitBlockRequestMessage(block *MsgBlock) *SubmitBlockRequestMessage {
|
||||||
return &SubmitBlockRequestMessage{
|
return &SubmitBlockRequestMessage{
|
||||||
Block: block,
|
Block: block,
|
||||||
}
|
}
|
||||||
@@ -53,48 +53,7 @@ func (msg *SubmitBlockResponseMessage) Command() MessageCommand {
|
|||||||
return CmdSubmitBlockResponseMessage
|
return CmdSubmitBlockResponseMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSubmitBlockResponseMessage returns an instance of the message
|
// NewSubmitBlockResponseMessage returns a instance of the message
|
||||||
func NewSubmitBlockResponseMessage() *SubmitBlockResponseMessage {
|
func NewSubmitBlockResponseMessage() *SubmitBlockResponseMessage {
|
||||||
return &SubmitBlockResponseMessage{}
|
return &SubmitBlockResponseMessage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCBlock is a kaspad block representation meant to be
|
|
||||||
// used over RPC
|
|
||||||
type RPCBlock struct {
|
|
||||||
Header *RPCBlockHeader
|
|
||||||
Transactions []*RPCTransaction
|
|
||||||
VerboseData *RPCBlockVerboseData
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCBlockHeader is a kaspad block header representation meant to be
|
|
||||||
// used over RPC
|
|
||||||
type RPCBlockHeader struct {
|
|
||||||
Version uint32
|
|
||||||
Parents []*RPCBlockLevelParents
|
|
||||||
HashMerkleRoot string
|
|
||||||
AcceptedIDMerkleRoot string
|
|
||||||
UTXOCommitment string
|
|
||||||
Timestamp int64
|
|
||||||
Bits uint32
|
|
||||||
Nonce uint64
|
|
||||||
DAAScore uint64
|
|
||||||
BlueScore uint64
|
|
||||||
BlueWork string
|
|
||||||
PruningPoint string
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCBlockLevelParents holds parent hashes for one block level
|
|
||||||
type RPCBlockLevelParents struct {
|
|
||||||
ParentHashes []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCBlockVerboseData holds verbose data about a block
|
|
||||||
type RPCBlockVerboseData struct {
|
|
||||||
Hash string
|
|
||||||
Difficulty float64
|
|
||||||
SelectedParentHash string
|
|
||||||
TransactionIDs []string
|
|
||||||
IsHeaderOnly bool
|
|
||||||
BlueScore uint64
|
|
||||||
ChildrenHashes []string
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package appmessage
|
|||||||
type SubmitTransactionRequestMessage struct {
|
type SubmitTransactionRequestMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Transaction *RPCTransaction
|
Transaction *RPCTransaction
|
||||||
AllowOrphan bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@@ -14,10 +13,9 @@ func (msg *SubmitTransactionRequestMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSubmitTransactionRequestMessage returns a instance of the message
|
// NewSubmitTransactionRequestMessage returns a instance of the message
|
||||||
func NewSubmitTransactionRequestMessage(transaction *RPCTransaction, allowOrphan bool) *SubmitTransactionRequestMessage {
|
func NewSubmitTransactionRequestMessage(transaction *RPCTransaction) *SubmitTransactionRequestMessage {
|
||||||
return &SubmitTransactionRequestMessage{
|
return &SubmitTransactionRequestMessage{
|
||||||
Transaction: transaction,
|
Transaction: transaction,
|
||||||
AllowOrphan: allowOrphan,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +49,8 @@ type RPCTransaction struct {
|
|||||||
LockTime uint64
|
LockTime uint64
|
||||||
SubnetworkID string
|
SubnetworkID string
|
||||||
Gas uint64
|
Gas uint64
|
||||||
|
PayloadHash string
|
||||||
Payload string
|
Payload string
|
||||||
VerboseData *RPCTransactionVerboseData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCTransactionInput is a kaspad transaction input representation
|
// RPCTransactionInput is a kaspad transaction input representation
|
||||||
@@ -61,8 +59,6 @@ type RPCTransactionInput struct {
|
|||||||
PreviousOutpoint *RPCOutpoint
|
PreviousOutpoint *RPCOutpoint
|
||||||
SignatureScript string
|
SignatureScript string
|
||||||
Sequence uint64
|
Sequence uint64
|
||||||
SigOpCount byte
|
|
||||||
VerboseData *RPCTransactionInputVerboseData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCScriptPublicKey is a kaspad ScriptPublicKey representation
|
// RPCScriptPublicKey is a kaspad ScriptPublicKey representation
|
||||||
@@ -76,7 +72,6 @@ type RPCScriptPublicKey struct {
|
|||||||
type RPCTransactionOutput struct {
|
type RPCTransactionOutput struct {
|
||||||
Amount uint64
|
Amount uint64
|
||||||
ScriptPublicKey *RPCScriptPublicKey
|
ScriptPublicKey *RPCScriptPublicKey
|
||||||
VerboseData *RPCTransactionOutputVerboseData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCOutpoint is a kaspad outpoint representation meant to be used
|
// RPCOutpoint is a kaspad outpoint representation meant to be used
|
||||||
@@ -91,25 +86,6 @@ type RPCOutpoint struct {
|
|||||||
type RPCUTXOEntry struct {
|
type RPCUTXOEntry struct {
|
||||||
Amount uint64
|
Amount uint64
|
||||||
ScriptPublicKey *RPCScriptPublicKey
|
ScriptPublicKey *RPCScriptPublicKey
|
||||||
BlockDAAScore uint64
|
BlockBlueScore uint64
|
||||||
IsCoinbase bool
|
IsCoinbase bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCTransactionVerboseData holds verbose data about a transaction
|
|
||||||
type RPCTransactionVerboseData struct {
|
|
||||||
TransactionID string
|
|
||||||
Hash string
|
|
||||||
Mass uint64
|
|
||||||
BlockHash string
|
|
||||||
BlockTime uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCTransactionInputVerboseData holds data about a transaction input
|
|
||||||
type RPCTransactionInputVerboseData struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCTransactionOutputVerboseData holds data about a transaction output
|
|
||||||
type RPCTransactionOutputVerboseData struct {
|
|
||||||
ScriptPublicKeyType string
|
|
||||||
ScriptPublicKeyAddress string
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,19 +4,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
"github.com/kaspanet/kaspad/domain/utxoindex"
|
||||||
|
|
||||||
|
infrastructuredatabase "github.com/kaspanet/kaspad/infrastructure/db/database"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/id"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/protocol"
|
"github.com/kaspanet/kaspad/app/protocol"
|
||||||
"github.com/kaspanet/kaspad/app/rpc"
|
"github.com/kaspanet/kaspad/app/rpc"
|
||||||
"github.com/kaspanet/kaspad/domain"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
|
||||||
"github.com/kaspanet/kaspad/domain/utxoindex"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
||||||
infrastructuredatabase "github.com/kaspanet/kaspad/infrastructure/db/database"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/connmanager"
|
"github.com/kaspanet/kaspad/infrastructure/network/connmanager"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/network/dnsseed"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/id"
|
|
||||||
"github.com/kaspanet/kaspad/util/panics"
|
"github.com/kaspanet/kaspad/util/panics"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,6 +50,8 @@ func (a *ComponentManager) Start() {
|
|||||||
panics.Exit(log, fmt.Sprintf("Error starting the net adapter: %+v", err))
|
panics.Exit(log, fmt.Sprintf("Error starting the net adapter: %+v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.maybeSeedFromDNS()
|
||||||
|
|
||||||
a.connectionManager.Start()
|
a.connectionManager.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,8 +72,6 @@ func (a *ComponentManager) Stop() {
|
|||||||
log.Errorf("Error stopping the net adapter: %+v", err)
|
log.Errorf("Error stopping the net adapter: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.protocolManager.Close()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,16 +80,7 @@ func (a *ComponentManager) Stop() {
|
|||||||
func NewComponentManager(cfg *config.Config, db infrastructuredatabase.Database, interrupt chan<- struct{}) (
|
func NewComponentManager(cfg *config.Config, db infrastructuredatabase.Database, interrupt chan<- struct{}) (
|
||||||
*ComponentManager, error) {
|
*ComponentManager, error) {
|
||||||
|
|
||||||
consensusConfig := consensus.Config{
|
domain, err := domain.New(cfg.ActiveNetParams, db, cfg.IsArchivalNode)
|
||||||
Params: *cfg.ActiveNetParams,
|
|
||||||
IsArchival: cfg.IsArchivalNode,
|
|
||||||
EnableSanityCheckPruningUTXOSet: cfg.EnableSanityCheckPruningUTXOSet,
|
|
||||||
}
|
|
||||||
mempoolConfig := mempool.DefaultConfig(&consensusConfig.Params)
|
|
||||||
mempoolConfig.MaximumOrphanTransactionCount = cfg.MaxOrphanTxs
|
|
||||||
mempoolConfig.MinimumRelayTransactionFee = cfg.MinRelayTxFee
|
|
||||||
|
|
||||||
domain, err := domain.New(&consensusConfig, mempoolConfig, db)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -158,6 +153,23 @@ func setupRPC(
|
|||||||
return rpcManager
|
return rpcManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ComponentManager) maybeSeedFromDNS() {
|
||||||
|
if !a.cfg.DisableDNSSeed {
|
||||||
|
dnsseed.SeedFromDNS(a.cfg.NetParams(), a.cfg.DNSSeed, appmessage.SFNodeNetwork, false, nil,
|
||||||
|
a.cfg.Lookup, func(addresses []*appmessage.NetAddress) {
|
||||||
|
// Kaspad uses a lookup of the dns seeder here. Since seeder returns
|
||||||
|
// IPs of nodes and not its own IP, we can not know real IP of
|
||||||
|
// source. So we'll take first returned address as source.
|
||||||
|
a.addressManager.AddAddresses(addresses...)
|
||||||
|
})
|
||||||
|
|
||||||
|
dnsseed.SeedFromGRPC(a.cfg.NetParams(), a.cfg.GRPCSeed, appmessage.SFNodeNetwork, false, nil,
|
||||||
|
func(addresses []*appmessage.NetAddress) {
|
||||||
|
a.addressManager.AddAddresses(addresses...)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// P2PNodeID returns the network ID associated with this ComponentManager
|
// P2PNodeID returns the network ID associated with this ComponentManager
|
||||||
func (a *ComponentManager) P2PNodeID() *id.ID {
|
func (a *ComponentManager) P2PNodeID() *id.ID {
|
||||||
return a.netAdapter.ID()
|
return a.netAdapter.ID()
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
const currentDatabaseVersion = 1
|
|
||||||
|
|
||||||
func checkDatabaseVersion(dbPath string) (err error) {
|
|
||||||
versionFileName := versionFilePath(dbPath)
|
|
||||||
|
|
||||||
versionBytes, err := os.ReadFile(versionFileName)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) { // If version file doesn't exist, we assume that the database is new
|
|
||||||
return createDatabaseVersionFile(dbPath, versionFileName)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
databaseVersion, err := strconv.Atoi(string(versionBytes))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if databaseVersion != currentDatabaseVersion {
|
|
||||||
// TODO: Once there's more then one database version, it might make sense to add upgrade logic at this point
|
|
||||||
return errors.Errorf("Invalid database version %d. Expected version: %d", databaseVersion, currentDatabaseVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createDatabaseVersionFile(dbPath string, versionFileName string) error {
|
|
||||||
err := os.MkdirAll(dbPath, 0700)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
versionFile, err := os.Create(versionFileName)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
defer versionFile.Close()
|
|
||||||
|
|
||||||
versionString := strconv.Itoa(currentDatabaseVersion)
|
|
||||||
_, err = versionFile.Write([]byte(versionString))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func versionFilePath(dbPath string) string {
|
|
||||||
dbVersionFileName := path.Join(dbPath, "version")
|
|
||||||
return dbVersionFileName
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
package flowcontext
|
package flowcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/blockrelay"
|
"github.com/kaspanet/kaspad/app/protocol/flows/blockrelay"
|
||||||
)
|
)
|
||||||
@@ -38,14 +37,12 @@ func (f *FlowContext) OnNewBlock(block *externalapi.DomainBlock,
|
|||||||
newBlockInsertionResults = append(newBlockInsertionResults, unorphaningResult.blockInsertionResult)
|
newBlockInsertionResults = append(newBlockInsertionResults, unorphaningResult.blockInsertionResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
allAcceptedTransactions := make([]*externalapi.DomainTransaction, 0)
|
|
||||||
for i, newBlock := range newBlocks {
|
for i, newBlock := range newBlocks {
|
||||||
log.Debugf("OnNewBlock: passing block %s transactions to mining manager", hash)
|
log.Debugf("OnNewBlock: passing block %s transactions to mining manager", hash)
|
||||||
acceptedTransactions, err := f.Domain().MiningManager().HandleNewBlockTransactions(newBlock.Transactions)
|
_, err = f.Domain().MiningManager().HandleNewBlockTransactions(newBlock.Transactions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
allAcceptedTransactions = append(allAcceptedTransactions, acceptedTransactions...)
|
|
||||||
|
|
||||||
if f.onBlockAddedToDAGHandler != nil {
|
if f.onBlockAddedToDAGHandler != nil {
|
||||||
log.Debugf("OnNewBlock: calling f.onBlockAddedToDAGHandler for block %s", hash)
|
log.Debugf("OnNewBlock: calling f.onBlockAddedToDAGHandler for block %s", hash)
|
||||||
@@ -57,7 +54,7 @@ func (f *FlowContext) OnNewBlock(block *externalapi.DomainBlock,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.broadcastTransactionsAfterBlockAdded(newBlocks, allAcceptedTransactions)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnPruningPointUTXOSetOverride calls the handler function whenever the UTXO set
|
// OnPruningPointUTXOSetOverride calls the handler function whenever the UTXO set
|
||||||
@@ -70,7 +67,9 @@ func (f *FlowContext) OnPruningPointUTXOSetOverride() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *FlowContext) broadcastTransactionsAfterBlockAdded(
|
func (f *FlowContext) broadcastTransactionsAfterBlockAdded(
|
||||||
addedBlocks []*externalapi.DomainBlock, transactionsAcceptedToMempool []*externalapi.DomainTransaction) error {
|
block *externalapi.DomainBlock, transactionsAcceptedToMempool []*externalapi.DomainTransaction) error {
|
||||||
|
|
||||||
|
f.updateTransactionsToRebroadcast(block)
|
||||||
|
|
||||||
// Don't relay transactions when in IBD.
|
// Don't relay transactions when in IBD.
|
||||||
if f.IsIBDRunning() {
|
if f.IsIBDRunning() {
|
||||||
@@ -79,12 +78,7 @@ func (f *FlowContext) broadcastTransactionsAfterBlockAdded(
|
|||||||
|
|
||||||
var txIDsToRebroadcast []*externalapi.DomainTransactionID
|
var txIDsToRebroadcast []*externalapi.DomainTransactionID
|
||||||
if f.shouldRebroadcastTransactions() {
|
if f.shouldRebroadcastTransactions() {
|
||||||
txsToRebroadcast, err := f.Domain().MiningManager().RevalidateHighPriorityTransactions()
|
txIDsToRebroadcast = f.txIDsToRebroadcast()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
txIDsToRebroadcast = consensushashing.TransactionIDs(txsToRebroadcast)
|
|
||||||
f.lastRebroadcastTime = time.Now()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
txIDsToBroadcast := make([]*externalapi.DomainTransactionID, len(transactionsAcceptedToMempool)+len(txIDsToRebroadcast))
|
txIDsToBroadcast := make([]*externalapi.DomainTransactionID, len(transactionsAcceptedToMempool)+len(txIDsToRebroadcast))
|
||||||
@@ -95,7 +89,15 @@ func (f *FlowContext) broadcastTransactionsAfterBlockAdded(
|
|||||||
for i, txID := range txIDsToRebroadcast {
|
for i, txID := range txIDsToRebroadcast {
|
||||||
txIDsToBroadcast[offset+i] = txID
|
txIDsToBroadcast[offset+i] = txID
|
||||||
}
|
}
|
||||||
return f.EnqueueTransactionIDsForPropagation(txIDsToBroadcast)
|
|
||||||
|
if len(txIDsToBroadcast) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(txIDsToBroadcast) > appmessage.MaxInvPerTxInvMsg {
|
||||||
|
txIDsToBroadcast = txIDsToBroadcast[:appmessage.MaxInvPerTxInvMsg]
|
||||||
|
}
|
||||||
|
inv := appmessage.NewMsgInvTransaction(txIDsToBroadcast)
|
||||||
|
return f.Broadcast(inv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SharedRequestedBlocks returns a *blockrelay.SharedRequestedBlocks for sharing
|
// SharedRequestedBlocks returns a *blockrelay.SharedRequestedBlocks for sharing
|
||||||
@@ -110,7 +112,7 @@ func (f *FlowContext) AddBlock(block *externalapi.DomainBlock) error {
|
|||||||
return protocolerrors.Errorf(false, "cannot add header only block")
|
return protocolerrors.Errorf(false, "cannot add header only block")
|
||||||
}
|
}
|
||||||
|
|
||||||
blockInsertionResult, err := f.Domain().Consensus().ValidateAndInsertBlock(block, true)
|
blockInsertionResult, err := f.Domain().Consensus().ValidateAndInsertBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.As(err, &ruleerrors.RuleError{}) {
|
if errors.As(err, &ruleerrors.RuleError{}) {
|
||||||
log.Warnf("Validation failed for block %s: %s", consensushashing.BlockHash(block), err)
|
log.Warnf("Validation failed for block %s: %s", consensushashing.BlockHash(block), err)
|
||||||
@@ -157,6 +159,7 @@ func (f *FlowContext) UnsetIBDRunning() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f.ibdPeer = nil
|
f.ibdPeer = nil
|
||||||
|
log.Infof("IBD finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
// IBDPeer returns the current IBD peer or null if the node is not
|
// IBDPeer returns the current IBD peer or null if the node is not
|
||||||
|
|||||||
@@ -29,8 +29,3 @@ func (*FlowContext) HandleError(err error, flowName string, isStopping *uint32,
|
|||||||
errChan <- err
|
errChan <- err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRecoverableError returns whether the error is recoverable
|
|
||||||
func (*FlowContext) IsRecoverableError(err error) bool {
|
|
||||||
return err == nil || errors.Is(err, router.ErrRouteClosed) || errors.As(err, &protocolerrors.ProtocolError{})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package flowcontext
|
package flowcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/util/mstime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/util/mstime"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
"github.com/kaspanet/kaspad/domain"
|
||||||
@@ -47,8 +46,10 @@ type FlowContext struct {
|
|||||||
onPruningPointUTXOSetOverrideHandler OnPruningPointUTXOSetOverrideHandler
|
onPruningPointUTXOSetOverrideHandler OnPruningPointUTXOSetOverrideHandler
|
||||||
onTransactionAddedToMempoolHandler OnTransactionAddedToMempoolHandler
|
onTransactionAddedToMempoolHandler OnTransactionAddedToMempoolHandler
|
||||||
|
|
||||||
lastRebroadcastTime time.Time
|
transactionsToRebroadcastLock sync.Mutex
|
||||||
sharedRequestedTransactions *transactionrelay.SharedRequestedTransactions
|
transactionsToRebroadcast map[externalapi.DomainTransactionID]*externalapi.DomainTransaction
|
||||||
|
lastRebroadcastTime time.Time
|
||||||
|
sharedRequestedTransactions *transactionrelay.SharedRequestedTransactions
|
||||||
|
|
||||||
sharedRequestedBlocks *blockrelay.SharedRequestedBlocks
|
sharedRequestedBlocks *blockrelay.SharedRequestedBlocks
|
||||||
|
|
||||||
@@ -60,12 +61,6 @@ type FlowContext struct {
|
|||||||
|
|
||||||
orphans map[externalapi.DomainHash]*externalapi.DomainBlock
|
orphans map[externalapi.DomainHash]*externalapi.DomainBlock
|
||||||
orphansMutex sync.RWMutex
|
orphansMutex sync.RWMutex
|
||||||
|
|
||||||
transactionIDsToPropagate []*externalapi.DomainTransactionID
|
|
||||||
lastTransactionIDPropagationTime time.Time
|
|
||||||
transactionIDPropagationLock sync.Mutex
|
|
||||||
|
|
||||||
shutdownChan chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new instance of FlowContext.
|
// New returns a new instance of FlowContext.
|
||||||
@@ -73,33 +68,20 @@ func New(cfg *config.Config, domain domain.Domain, addressManager *addressmanage
|
|||||||
netAdapter *netadapter.NetAdapter, connectionManager *connmanager.ConnectionManager) *FlowContext {
|
netAdapter *netadapter.NetAdapter, connectionManager *connmanager.ConnectionManager) *FlowContext {
|
||||||
|
|
||||||
return &FlowContext{
|
return &FlowContext{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
netAdapter: netAdapter,
|
netAdapter: netAdapter,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
addressManager: addressManager,
|
addressManager: addressManager,
|
||||||
connectionManager: connectionManager,
|
connectionManager: connectionManager,
|
||||||
sharedRequestedTransactions: transactionrelay.NewSharedRequestedTransactions(),
|
sharedRequestedTransactions: transactionrelay.NewSharedRequestedTransactions(),
|
||||||
sharedRequestedBlocks: blockrelay.NewSharedRequestedBlocks(),
|
sharedRequestedBlocks: blockrelay.NewSharedRequestedBlocks(),
|
||||||
peers: make(map[id.ID]*peerpkg.Peer),
|
peers: make(map[id.ID]*peerpkg.Peer),
|
||||||
orphans: make(map[externalapi.DomainHash]*externalapi.DomainBlock),
|
transactionsToRebroadcast: make(map[externalapi.DomainTransactionID]*externalapi.DomainTransaction),
|
||||||
timeStarted: mstime.Now().UnixMilliseconds(),
|
orphans: make(map[externalapi.DomainHash]*externalapi.DomainBlock),
|
||||||
transactionIDsToPropagate: []*externalapi.DomainTransactionID{},
|
timeStarted: mstime.Now().UnixMilliseconds(),
|
||||||
lastTransactionIDPropagationTime: time.Now(),
|
|
||||||
shutdownChan: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close signals to all flows the the protocol manager is closed.
|
|
||||||
func (f *FlowContext) Close() {
|
|
||||||
close(f.shutdownChan)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShutdownChan is a chan where flows can subscribe to shutdown
|
|
||||||
// event.
|
|
||||||
func (f *FlowContext) ShutdownChan() <-chan struct{} {
|
|
||||||
return f.shutdownChan
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOnBlockAddedToDAGHandler sets the onBlockAddedToDAG handler
|
// SetOnBlockAddedToDAGHandler sets the onBlockAddedToDAG handler
|
||||||
func (f *FlowContext) SetOnBlockAddedToDAGHandler(onBlockAddedToDAGHandler OnBlockAddedToDAGHandler) {
|
func (f *FlowContext) SetOnBlockAddedToDAGHandler(onBlockAddedToDAGHandler OnBlockAddedToDAGHandler) {
|
||||||
f.onBlockAddedToDAGHandler = onBlockAddedToDAGHandler
|
f.onBlockAddedToDAGHandler = onBlockAddedToDAGHandler
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ func (f *FlowContext) UnorphanBlocks(rootBlock *externalapi.DomainBlock) ([]*Uno
|
|||||||
orphanBlock := f.orphans[orphanHash]
|
orphanBlock := f.orphans[orphanHash]
|
||||||
|
|
||||||
log.Debugf("Considering to unorphan block %s with parents %s",
|
log.Debugf("Considering to unorphan block %s with parents %s",
|
||||||
orphanHash, orphanBlock.Header.DirectParents())
|
orphanHash, orphanBlock.Header.ParentHashes())
|
||||||
|
|
||||||
canBeUnorphaned := true
|
canBeUnorphaned := true
|
||||||
for _, orphanBlockParentHash := range orphanBlock.Header.DirectParents() {
|
for _, orphanBlockParentHash := range orphanBlock.Header.ParentHashes() {
|
||||||
orphanBlockParentInfo, err := f.domain.Consensus().GetBlockInfo(orphanBlockParentHash)
|
orphanBlockParentInfo, err := f.domain.Consensus().GetBlockInfo(orphanBlockParentHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -133,7 +133,7 @@ func (f *FlowContext) addChildOrphansToProcessQueue(blockHash *externalapi.Domai
|
|||||||
func (f *FlowContext) findChildOrphansOfBlock(blockHash *externalapi.DomainHash) []externalapi.DomainHash {
|
func (f *FlowContext) findChildOrphansOfBlock(blockHash *externalapi.DomainHash) []externalapi.DomainHash {
|
||||||
var childOrphans []externalapi.DomainHash
|
var childOrphans []externalapi.DomainHash
|
||||||
for orphanHash, orphanBlock := range f.orphans {
|
for orphanHash, orphanBlock := range f.orphans {
|
||||||
for _, orphanBlockParentHash := range orphanBlock.Header.DirectParents() {
|
for _, orphanBlockParentHash := range orphanBlock.Header.ParentHashes() {
|
||||||
if orphanBlockParentHash.Equal(blockHash) {
|
if orphanBlockParentHash.Equal(blockHash) {
|
||||||
childOrphans = append(childOrphans, orphanHash)
|
childOrphans = append(childOrphans, orphanHash)
|
||||||
break
|
break
|
||||||
@@ -150,7 +150,7 @@ func (f *FlowContext) unorphanBlock(orphanHash externalapi.DomainHash) (*externa
|
|||||||
}
|
}
|
||||||
delete(f.orphans, orphanHash)
|
delete(f.orphans, orphanHash)
|
||||||
|
|
||||||
blockInsertionResult, err := f.domain.Consensus().ValidateAndInsertBlock(orphanBlock, true)
|
blockInsertionResult, err := f.domain.Consensus().ValidateAndInsertBlock(orphanBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.As(err, &ruleerrors.RuleError{}) {
|
if errors.As(err, &ruleerrors.RuleError{}) {
|
||||||
log.Warnf("Validation failed for orphan block %s: %s", orphanHash, err)
|
log.Warnf("Validation failed for orphan block %s: %s", orphanHash, err)
|
||||||
@@ -201,7 +201,7 @@ func (f *FlowContext) GetOrphanRoots(orphan *externalapi.DomainHash) ([]*externa
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, parent := range block.Header.DirectParents() {
|
for _, parent := range block.Header.ParentHashes() {
|
||||||
if !addedToQueueSet.Contains(parent) {
|
if !addedToQueueSet.Contains(parent) {
|
||||||
queue = append(queue, parent)
|
queue = append(queue, parent)
|
||||||
addedToQueueSet.Add(parent)
|
addedToQueueSet.Add(parent)
|
||||||
|
|||||||
@@ -9,18 +9,31 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TransactionIDPropagationInterval is the interval between transaction IDs propagations
|
|
||||||
const TransactionIDPropagationInterval = 500 * time.Millisecond
|
|
||||||
|
|
||||||
// AddTransaction adds transaction to the mempool and propagates it.
|
// AddTransaction adds transaction to the mempool and propagates it.
|
||||||
func (f *FlowContext) AddTransaction(tx *externalapi.DomainTransaction, allowOrphan bool) error {
|
func (f *FlowContext) AddTransaction(tx *externalapi.DomainTransaction) error {
|
||||||
acceptedTransactions, err := f.Domain().MiningManager().ValidateAndInsertTransaction(tx, true, allowOrphan)
|
f.transactionsToRebroadcastLock.Lock()
|
||||||
|
defer f.transactionsToRebroadcastLock.Unlock()
|
||||||
|
|
||||||
|
err := f.Domain().MiningManager().ValidateAndInsertTransaction(tx, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
acceptedTransactionIDs := consensushashing.TransactionIDs(acceptedTransactions)
|
transactionID := consensushashing.TransactionID(tx)
|
||||||
return f.EnqueueTransactionIDsForPropagation(acceptedTransactionIDs)
|
f.transactionsToRebroadcast[*transactionID] = tx
|
||||||
|
inv := appmessage.NewMsgInvTransaction([]*externalapi.DomainTransactionID{transactionID})
|
||||||
|
return f.Broadcast(inv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FlowContext) updateTransactionsToRebroadcast(block *externalapi.DomainBlock) {
|
||||||
|
f.transactionsToRebroadcastLock.Lock()
|
||||||
|
defer f.transactionsToRebroadcastLock.Unlock()
|
||||||
|
// Note: if the block is red, its transactions won't be rebroadcasted
|
||||||
|
// anymore, although they are not included in the UTXO set.
|
||||||
|
// This is probably ok, since red blocks are quite rare.
|
||||||
|
for _, tx := range block.Transactions {
|
||||||
|
delete(f.transactionsToRebroadcast, *consensushashing.TransactionID(tx))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FlowContext) shouldRebroadcastTransactions() bool {
|
func (f *FlowContext) shouldRebroadcastTransactions() bool {
|
||||||
@@ -28,6 +41,19 @@ func (f *FlowContext) shouldRebroadcastTransactions() bool {
|
|||||||
return time.Since(f.lastRebroadcastTime) > rebroadcastInterval
|
return time.Since(f.lastRebroadcastTime) > rebroadcastInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FlowContext) txIDsToRebroadcast() []*externalapi.DomainTransactionID {
|
||||||
|
f.transactionsToRebroadcastLock.Lock()
|
||||||
|
defer f.transactionsToRebroadcastLock.Unlock()
|
||||||
|
|
||||||
|
txIDs := make([]*externalapi.DomainTransactionID, len(f.transactionsToRebroadcast))
|
||||||
|
i := 0
|
||||||
|
for _, tx := range f.transactionsToRebroadcast {
|
||||||
|
txIDs[i] = consensushashing.TransactionID(tx)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return txIDs
|
||||||
|
}
|
||||||
|
|
||||||
// SharedRequestedTransactions returns a *transactionrelay.SharedRequestedTransactions for sharing
|
// SharedRequestedTransactions returns a *transactionrelay.SharedRequestedTransactions for sharing
|
||||||
// data about requested transactions between different peers.
|
// data about requested transactions between different peers.
|
||||||
func (f *FlowContext) SharedRequestedTransactions() *transactionrelay.SharedRequestedTransactions {
|
func (f *FlowContext) SharedRequestedTransactions() *transactionrelay.SharedRequestedTransactions {
|
||||||
@@ -41,42 +67,3 @@ func (f *FlowContext) OnTransactionAddedToMempool() {
|
|||||||
f.onTransactionAddedToMempoolHandler()
|
f.onTransactionAddedToMempoolHandler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnqueueTransactionIDsForPropagation add the given transactions IDs to a set of IDs to
|
|
||||||
// propagate. The IDs will be broadcast to all peers within a single transaction Inv message.
|
|
||||||
// The broadcast itself may happen only during a subsequent call to this method
|
|
||||||
func (f *FlowContext) EnqueueTransactionIDsForPropagation(transactionIDs []*externalapi.DomainTransactionID) error {
|
|
||||||
f.transactionIDPropagationLock.Lock()
|
|
||||||
defer f.transactionIDPropagationLock.Unlock()
|
|
||||||
|
|
||||||
f.transactionIDsToPropagate = append(f.transactionIDsToPropagate, transactionIDs...)
|
|
||||||
|
|
||||||
return f.maybePropagateTransactions()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FlowContext) maybePropagateTransactions() error {
|
|
||||||
if time.Since(f.lastTransactionIDPropagationTime) < TransactionIDPropagationInterval &&
|
|
||||||
len(f.transactionIDsToPropagate) < appmessage.MaxInvPerTxInvMsg {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for len(f.transactionIDsToPropagate) > 0 {
|
|
||||||
transactionIDsToBroadcast := f.transactionIDsToPropagate
|
|
||||||
if len(transactionIDsToBroadcast) > appmessage.MaxInvPerTxInvMsg {
|
|
||||||
transactionIDsToBroadcast = f.transactionIDsToPropagate[:len(transactionIDsToBroadcast)]
|
|
||||||
}
|
|
||||||
log.Debugf("Transaction propagation: broadcasting %d transactions", len(transactionIDsToBroadcast))
|
|
||||||
|
|
||||||
inv := appmessage.NewMsgInvTransaction(transactionIDsToBroadcast)
|
|
||||||
err := f.Broadcast(inv)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
f.transactionIDsToPropagate = f.transactionIDsToPropagate[len(transactionIDsToBroadcast):]
|
|
||||||
}
|
|
||||||
|
|
||||||
f.lastTransactionIDPropagationTime = time.Now()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) sendGetBlockLocator(highHash *externalapi.DomainHash, limit uint32) error {
|
func (flow *handleRelayInvsFlow) sendGetBlockLocator(lowHash *externalapi.DomainHash,
|
||||||
msgGetBlockLocator := appmessage.NewMsgRequestBlockLocator(highHash, limit)
|
highHash *externalapi.DomainHash, limit uint32) error {
|
||||||
|
|
||||||
|
msgGetBlockLocator := appmessage.NewMsgRequestBlockLocator(lowHash, highHash, limit)
|
||||||
return flow.outgoingRoute.Enqueue(msgGetBlockLocator)
|
return flow.outgoingRoute.Enqueue(msgGetBlockLocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/app/protocol/peer"
|
"github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
||||||
"github.com/kaspanet/kaspad/domain"
|
"github.com/kaspanet/kaspad/domain"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,9 +44,7 @@ func HandleIBDBlockLocator(context HandleIBDBlockLocatorContext, incomingRoute *
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !blockInfo.Exists {
|
||||||
// The IBD block locator is checking only existing blocks with bodies.
|
|
||||||
if !blockInfo.Exists || blockInfo.BlockStatus == externalapi.StatusHeaderOnly {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func HandleIBDBlockRequests(context HandleIBDBlockRequestsContext, incomingRoute
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("sent %d out of %d", i+1, len(msgRequestIBDBlocks.Hashes))
|
log.Debugf("sent %d out of %d", i, len(msgRequestIBDBlocks.Hashes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
package blockrelay
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PruningPointAndItsAnticoneRequestsContext is the interface for the context needed for the HandlePruningPointAndItsAnticoneRequests flow.
|
|
||||||
type PruningPointAndItsAnticoneRequestsContext interface {
|
|
||||||
Domain() domain.Domain
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandlePruningPointAndItsAnticoneRequests listens to appmessage.MsgRequestPruningPointAndItsAnticone messages and sends
|
|
||||||
// the pruning point and its anticone to the requesting peer.
|
|
||||||
func HandlePruningPointAndItsAnticoneRequests(context PruningPointAndItsAnticoneRequestsContext, incomingRoute *router.Route,
|
|
||||||
outgoingRoute *router.Route, peer *peerpkg.Peer) error {
|
|
||||||
|
|
||||||
for {
|
|
||||||
_, err := incomingRoute.Dequeue()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Got request for pruning point and its anticone from %s", peer)
|
|
||||||
|
|
||||||
pruningPointHeaders, err := context.Domain().Consensus().PruningPointHeaders()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msgPruningPointHeaders := make([]*appmessage.MsgBlockHeader, len(pruningPointHeaders))
|
|
||||||
for i, header := range pruningPointHeaders {
|
|
||||||
msgPruningPointHeaders[i] = appmessage.DomainBlockHeaderToBlockHeader(header)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = outgoingRoute.Enqueue(appmessage.NewMsgPruningPoints(msgPruningPointHeaders))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks, err := context.Domain().Consensus().PruningPointAndItsAnticoneWithTrustedData()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, block := range blocks {
|
|
||||||
err = outgoingRoute.Enqueue(appmessage.DomainBlockWithTrustedDataToBlockWithTrustedData(block))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = outgoingRoute.Enqueue(appmessage.NewMsgDoneBlocksWithTrustedData())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Sent pruning point and its anticone to %s", peer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package blockrelay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
|
"github.com/kaspanet/kaspad/domain"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandlePruningPointHashRequestsFlowContext is the interface for the context needed for the handlePruningPointHashRequestsFlow flow.
|
||||||
|
type HandlePruningPointHashRequestsFlowContext interface {
|
||||||
|
Domain() domain.Domain
|
||||||
|
}
|
||||||
|
|
||||||
|
type handlePruningPointHashRequestsFlow struct {
|
||||||
|
HandlePruningPointHashRequestsFlowContext
|
||||||
|
incomingRoute, outgoingRoute *router.Route
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandlePruningPointHashRequests listens to appmessage.MsgRequestPruningPointHashMessage messages and sends
|
||||||
|
// the pruning point hash as response.
|
||||||
|
func HandlePruningPointHashRequests(context HandlePruningPointHashRequestsFlowContext, incomingRoute,
|
||||||
|
outgoingRoute *router.Route) error {
|
||||||
|
flow := &handlePruningPointHashRequestsFlow{
|
||||||
|
HandlePruningPointHashRequestsFlowContext: context,
|
||||||
|
incomingRoute: incomingRoute,
|
||||||
|
outgoingRoute: outgoingRoute,
|
||||||
|
}
|
||||||
|
|
||||||
|
return flow.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handlePruningPointHashRequestsFlow) start() error {
|
||||||
|
for {
|
||||||
|
_, err := flow.incomingRoute.Dequeue()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("Got request for a pruning point hash")
|
||||||
|
|
||||||
|
pruningPoint, err := flow.Domain().Consensus().PruningPoint()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = flow.outgoingRoute.Enqueue(appmessage.NewPruningPointHashMessage(pruningPoint))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("Sent pruning point hash %s", pruningPoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package blockrelay
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PruningPointProofRequestsContext is the interface for the context needed for the HandlePruningPointProofRequests flow.
|
|
||||||
type PruningPointProofRequestsContext interface {
|
|
||||||
Domain() domain.Domain
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandlePruningPointProofRequests listens to appmessage.MsgRequestPruningPointProof messages and sends
|
|
||||||
// the pruning point proof to the requesting peer.
|
|
||||||
func HandlePruningPointProofRequests(context PruningPointProofRequestsContext, incomingRoute *router.Route,
|
|
||||||
outgoingRoute *router.Route, peer *peerpkg.Peer) error {
|
|
||||||
|
|
||||||
for {
|
|
||||||
_, err := incomingRoute.Dequeue()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Got request for pruning point proof from %s", peer)
|
|
||||||
|
|
||||||
pruningPointProof, err := context.Domain().Consensus().BuildPruningPointProof()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pruningPointProofMessage := appmessage.DomainPruningPointProofToMsgPruningPointProof(pruningPointProof)
|
|
||||||
err = outgoingRoute.Enqueue(pruningPointProofMessage)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Sent pruning point proof to %s", peer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,6 @@ type RelayInvsContext interface {
|
|||||||
IsIBDRunning() bool
|
IsIBDRunning() bool
|
||||||
TrySetIBDRunning(ibdPeer *peerpkg.Peer) bool
|
TrySetIBDRunning(ibdPeer *peerpkg.Peer) bool
|
||||||
UnsetIBDRunning()
|
UnsetIBDRunning()
|
||||||
IsRecoverableError(err error) bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type handleRelayInvsFlow struct {
|
type handleRelayInvsFlow struct {
|
||||||
@@ -127,7 +126,7 @@ func (flow *handleRelayInvsFlow) start() error {
|
|||||||
}
|
}
|
||||||
if len(missingParents) > 0 {
|
if len(missingParents) > 0 {
|
||||||
log.Debugf("Block %s is orphan and has missing parents: %s", inv.Hash, missingParents)
|
log.Debugf("Block %s is orphan and has missing parents: %s", inv.Hash, missingParents)
|
||||||
err := flow.processOrphan(block)
|
err := flow.processOrphan(block, missingParents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,7 @@ func (flow *handleRelayInvsFlow) readMsgBlock() (msgBlock *appmessage.MsgBlock,
|
|||||||
|
|
||||||
func (flow *handleRelayInvsFlow) processBlock(block *externalapi.DomainBlock) ([]*externalapi.DomainHash, *externalapi.BlockInsertionResult, error) {
|
func (flow *handleRelayInvsFlow) processBlock(block *externalapi.DomainBlock) ([]*externalapi.DomainHash, *externalapi.BlockInsertionResult, error) {
|
||||||
blockHash := consensushashing.BlockHash(block)
|
blockHash := consensushashing.BlockHash(block)
|
||||||
blockInsertionResult, err := flow.Domain().Consensus().ValidateAndInsertBlock(block, true)
|
blockInsertionResult, err := flow.Domain().Consensus().ValidateAndInsertBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.As(err, &ruleerrors.RuleError{}) {
|
if !errors.As(err, &ruleerrors.RuleError{}) {
|
||||||
return nil, nil, errors.Wrapf(err, "failed to process block %s", blockHash)
|
return nil, nil, errors.Wrapf(err, "failed to process block %s", blockHash)
|
||||||
@@ -250,7 +249,7 @@ func (flow *handleRelayInvsFlow) relayBlock(block *externalapi.DomainBlock) erro
|
|||||||
return flow.Broadcast(appmessage.NewMsgInvBlock(blockHash))
|
return flow.Broadcast(appmessage.NewMsgInvBlock(blockHash))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) processOrphan(block *externalapi.DomainBlock) error {
|
func (flow *handleRelayInvsFlow) processOrphan(block *externalapi.DomainBlock, missingParents []*externalapi.DomainHash) error {
|
||||||
blockHash := consensushashing.BlockHash(block)
|
blockHash := consensushashing.BlockHash(block)
|
||||||
|
|
||||||
// Return if the block has been orphaned from elsewhere already
|
// Return if the block has been orphaned from elsewhere already
|
||||||
@@ -275,7 +274,7 @@ func (flow *handleRelayInvsFlow) processOrphan(block *externalapi.DomainBlock) e
|
|||||||
// Start IBD unless we already are in IBD
|
// Start IBD unless we already are in IBD
|
||||||
log.Debugf("Block %s is out of orphan resolution range. "+
|
log.Debugf("Block %s is out of orphan resolution range. "+
|
||||||
"Attempting to start IBD against it.", blockHash)
|
"Attempting to start IBD against it.", blockHash)
|
||||||
return flow.runIBDIfNotRunning(block)
|
return flow.runIBDIfNotRunning(blockHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isBlockInOrphanResolutionRange finds out whether the given blockHash should be
|
// isBlockInOrphanResolutionRange finds out whether the given blockHash should be
|
||||||
@@ -284,7 +283,8 @@ func (flow *handleRelayInvsFlow) processOrphan(block *externalapi.DomainBlock) e
|
|||||||
// In the response, if we know none of the hashes, we should retrieve the given
|
// In the response, if we know none of the hashes, we should retrieve the given
|
||||||
// blockHash via IBD. Otherwise, via unorphaning.
|
// blockHash via IBD. Otherwise, via unorphaning.
|
||||||
func (flow *handleRelayInvsFlow) isBlockInOrphanResolutionRange(blockHash *externalapi.DomainHash) (bool, error) {
|
func (flow *handleRelayInvsFlow) isBlockInOrphanResolutionRange(blockHash *externalapi.DomainHash) (bool, error) {
|
||||||
err := flow.sendGetBlockLocator(blockHash, orphanResolutionRange)
|
lowHash := flow.Config().ActiveNetParams.GenesisHash
|
||||||
|
err := flow.sendGetBlockLocator(lowHash, blockHash, orphanResolutionRange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,19 +32,20 @@ func HandleRequestBlockLocator(context RequestBlockLocatorContext, incomingRoute
|
|||||||
|
|
||||||
func (flow *handleRequestBlockLocatorFlow) start() error {
|
func (flow *handleRequestBlockLocatorFlow) start() error {
|
||||||
for {
|
for {
|
||||||
highHash, limit, err := flow.receiveGetBlockLocator()
|
lowHash, highHash, limit, err := flow.receiveGetBlockLocator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("Received getBlockLocator with highHash: %s, limit: %d", highHash, limit)
|
log.Debugf("Received getBlockLocator with lowHash: %s, highHash: %s, limit: %d",
|
||||||
|
lowHash, highHash, limit)
|
||||||
|
|
||||||
locator, err := flow.Domain().Consensus().CreateBlockLocatorFromPruningPoint(highHash, limit)
|
locator, err := flow.Domain().Consensus().CreateBlockLocator(lowHash, highHash, limit)
|
||||||
if err != nil || len(locator) == 0 {
|
if err != nil || len(locator) == 0 {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Received error from CreateBlockLocatorFromPruningPoint: %s", err)
|
log.Debugf("Received error from CreateBlockLocator: %s", err)
|
||||||
}
|
}
|
||||||
return protocolerrors.Errorf(true, "couldn't build a block "+
|
return protocolerrors.Errorf(true, "couldn't build a block "+
|
||||||
"locator between the pruning point and %s", highHash)
|
"locator between blocks %s and %s", lowHash, highHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = flow.sendBlockLocator(locator)
|
err = flow.sendBlockLocator(locator)
|
||||||
@@ -54,15 +55,16 @@ func (flow *handleRequestBlockLocatorFlow) start() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRequestBlockLocatorFlow) receiveGetBlockLocator() (highHash *externalapi.DomainHash, limit uint32, err error) {
|
func (flow *handleRequestBlockLocatorFlow) receiveGetBlockLocator() (lowHash *externalapi.DomainHash,
|
||||||
|
highHash *externalapi.DomainHash, limit uint32, err error) {
|
||||||
|
|
||||||
message, err := flow.incomingRoute.Dequeue()
|
message, err := flow.incomingRoute.Dequeue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, nil, 0, err
|
||||||
}
|
}
|
||||||
msgGetBlockLocator := message.(*appmessage.MsgRequestBlockLocator)
|
msgGetBlockLocator := message.(*appmessage.MsgRequestBlockLocator)
|
||||||
|
|
||||||
return msgGetBlockLocator.HighHash, msgGetBlockLocator.Limit, nil
|
return msgGetBlockLocator.LowHash, msgGetBlockLocator.HighHash, msgGetBlockLocator.Limit, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRequestBlockLocatorFlow) sendBlockLocator(locator externalapi.BlockLocator) error {
|
func (flow *handleRequestBlockLocatorFlow) sendBlockLocator(locator externalapi.BlockLocator) error {
|
||||||
|
|||||||
@@ -12,26 +12,26 @@ import (
|
|||||||
|
|
||||||
const ibdBatchSize = router.DefaultMaxMessages
|
const ibdBatchSize = router.DefaultMaxMessages
|
||||||
|
|
||||||
// RequestHeadersContext is the interface for the context needed for the HandleRequestHeaders flow.
|
// RequestIBDBlocksContext is the interface for the context needed for the HandleRequestHeaders flow.
|
||||||
type RequestHeadersContext interface {
|
type RequestIBDBlocksContext interface {
|
||||||
Domain() domain.Domain
|
Domain() domain.Domain
|
||||||
}
|
}
|
||||||
|
|
||||||
type handleRequestHeadersFlow struct {
|
type handleRequestHeadersFlow struct {
|
||||||
RequestHeadersContext
|
RequestIBDBlocksContext
|
||||||
incomingRoute, outgoingRoute *router.Route
|
incomingRoute, outgoingRoute *router.Route
|
||||||
peer *peer.Peer
|
peer *peer.Peer
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleRequestHeaders handles RequestHeaders messages
|
// HandleRequestHeaders handles RequestHeaders messages
|
||||||
func HandleRequestHeaders(context RequestHeadersContext, incomingRoute *router.Route,
|
func HandleRequestHeaders(context RequestIBDBlocksContext, incomingRoute *router.Route,
|
||||||
outgoingRoute *router.Route, peer *peer.Peer) error {
|
outgoingRoute *router.Route, peer *peer.Peer) error {
|
||||||
|
|
||||||
flow := &handleRequestHeadersFlow{
|
flow := &handleRequestHeadersFlow{
|
||||||
RequestHeadersContext: context,
|
RequestIBDBlocksContext: context,
|
||||||
incomingRoute: incomingRoute,
|
incomingRoute: incomingRoute,
|
||||||
outgoingRoute: outgoingRoute,
|
outgoingRoute: outgoingRoute,
|
||||||
peer: peer,
|
peer: peer,
|
||||||
}
|
}
|
||||||
return flow.start()
|
return flow.start()
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,8 @@ func (flow *handleRequestHeadersFlow) start() error {
|
|||||||
|
|
||||||
// GetHashesBetween is a relatively heavy operation so we limit it
|
// GetHashesBetween is a relatively heavy operation so we limit it
|
||||||
// in order to avoid locking the consensus for too long
|
// in order to avoid locking the consensus for too long
|
||||||
// maxBlocks MUST be >= MergeSetSizeLimit + 1
|
const maxBlueScoreDifference = 1 << 10
|
||||||
const maxBlocks = 1 << 10
|
blockHashes, err := flow.Domain().Consensus().GetHashesBetween(lowHash, highHash, maxBlueScoreDifference)
|
||||||
blockHashes, _, err := flow.Domain().Consensus().GetHashesBetween(lowHash, highHash, maxBlocks)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
package blockrelay
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/common"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/logger"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HandleRequestPruningPointUTXOSetContext is the interface for the context needed for the HandleRequestPruningPointUTXOSet flow.
|
|
||||||
type HandleRequestPruningPointUTXOSetContext interface {
|
|
||||||
Domain() domain.Domain
|
|
||||||
}
|
|
||||||
|
|
||||||
type handleRequestPruningPointUTXOSetFlow struct {
|
|
||||||
HandleRequestPruningPointUTXOSetContext
|
|
||||||
incomingRoute, outgoingRoute *router.Route
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleRequestPruningPointUTXOSet listens to appmessage.MsgRequestPruningPointUTXOSet messages and sends
|
|
||||||
// the pruning point UTXO set and block body.
|
|
||||||
func HandleRequestPruningPointUTXOSet(context HandleRequestPruningPointUTXOSetContext, incomingRoute,
|
|
||||||
outgoingRoute *router.Route) error {
|
|
||||||
|
|
||||||
flow := &handleRequestPruningPointUTXOSetFlow{
|
|
||||||
HandleRequestPruningPointUTXOSetContext: context,
|
|
||||||
incomingRoute: incomingRoute,
|
|
||||||
outgoingRoute: outgoingRoute,
|
|
||||||
}
|
|
||||||
|
|
||||||
return flow.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRequestPruningPointUTXOSetFlow) start() error {
|
|
||||||
for {
|
|
||||||
msgRequestPruningPointUTXOSet, err := flow.waitForRequestPruningPointUTXOSetMessages()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.handleRequestPruningPointUTXOSetMessage(msgRequestPruningPointUTXOSet)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRequestPruningPointUTXOSetFlow) handleRequestPruningPointUTXOSetMessage(
|
|
||||||
msgRequestPruningPointUTXOSet *appmessage.MsgRequestPruningPointUTXOSet) error {
|
|
||||||
|
|
||||||
onEnd := logger.LogAndMeasureExecutionTime(log, "handleRequestPruningPointUTXOSetFlow")
|
|
||||||
defer onEnd()
|
|
||||||
|
|
||||||
log.Debugf("Got request for pruning point UTXO set")
|
|
||||||
|
|
||||||
return flow.sendPruningPointUTXOSet(msgRequestPruningPointUTXOSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRequestPruningPointUTXOSetFlow) waitForRequestPruningPointUTXOSetMessages() (
|
|
||||||
*appmessage.MsgRequestPruningPointUTXOSet, error) {
|
|
||||||
|
|
||||||
message, err := flow.incomingRoute.Dequeue()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
msgRequestPruningPointUTXOSet, ok := message.(*appmessage.MsgRequestPruningPointUTXOSet)
|
|
||||||
if !ok {
|
|
||||||
return nil, protocolerrors.Errorf(true, "received unexpected message type. "+
|
|
||||||
"expected: %s, got: %s", appmessage.CmdRequestPruningPointUTXOSet, message.Command())
|
|
||||||
}
|
|
||||||
return msgRequestPruningPointUTXOSet, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRequestPruningPointUTXOSetFlow) sendPruningPointUTXOSet(
|
|
||||||
msgRequestPruningPointUTXOSet *appmessage.MsgRequestPruningPointUTXOSet) error {
|
|
||||||
|
|
||||||
// Send the UTXO set in `step`-sized chunks
|
|
||||||
const step = 1000
|
|
||||||
var fromOutpoint *externalapi.DomainOutpoint
|
|
||||||
chunksSent := 0
|
|
||||||
for {
|
|
||||||
pruningPointUTXOs, err := flow.Domain().Consensus().GetPruningPointUTXOs(
|
|
||||||
msgRequestPruningPointUTXOSet.PruningPointHash, fromOutpoint, step)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, ruleerrors.ErrWrongPruningPointHash) {
|
|
||||||
return flow.outgoingRoute.Enqueue(appmessage.NewMsgUnexpectedPruningPoint())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Retrieved %d UTXOs for pruning block %s",
|
|
||||||
len(pruningPointUTXOs), msgRequestPruningPointUTXOSet.PruningPointHash)
|
|
||||||
|
|
||||||
outpointAndUTXOEntryPairs :=
|
|
||||||
appmessage.DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs(pruningPointUTXOs)
|
|
||||||
err = flow.outgoingRoute.Enqueue(appmessage.NewMsgPruningPointUTXOSetChunk(outpointAndUTXOEntryPairs))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
finished := len(pruningPointUTXOs) < step
|
|
||||||
if finished && chunksSent%ibdBatchSize != 0 {
|
|
||||||
log.Debugf("Finished sending UTXOs for pruning block %s",
|
|
||||||
msgRequestPruningPointUTXOSet.PruningPointHash)
|
|
||||||
|
|
||||||
return flow.outgoingRoute.Enqueue(appmessage.NewMsgDonePruningPointUTXOSetChunks())
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(pruningPointUTXOs) > 0 {
|
|
||||||
fromOutpoint = pruningPointUTXOs[len(pruningPointUTXOs)-1].Outpoint
|
|
||||||
}
|
|
||||||
chunksSent++
|
|
||||||
|
|
||||||
// Wait for the peer to request more chunks every `ibdBatchSize` chunks
|
|
||||||
if chunksSent%ibdBatchSize == 0 {
|
|
||||||
message, err := flow.incomingRoute.DequeueWithTimeout(common.DefaultTimeout)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, ok := message.(*appmessage.MsgRequestNextPruningPointUTXOSetChunk)
|
|
||||||
if !ok {
|
|
||||||
return protocolerrors.Errorf(true, "received unexpected message type. "+
|
|
||||||
"expected: %s, got: %s", appmessage.CmdRequestNextPruningPointUTXOSetChunk, message.Command())
|
|
||||||
}
|
|
||||||
|
|
||||||
if finished {
|
|
||||||
log.Debugf("Finished sending UTXOs for pruning block %s",
|
|
||||||
msgRequestPruningPointUTXOSet.PruningPointHash)
|
|
||||||
|
|
||||||
return flow.outgoingRoute.Enqueue(appmessage.NewMsgDonePruningPointUTXOSetChunks())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package blockrelay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
|
"github.com/kaspanet/kaspad/app/protocol/common"
|
||||||
|
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
||||||
|
"github.com/kaspanet/kaspad/domain"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandleRequestPruningPointUTXOSetAndBlockContext is the interface for the context needed for the HandleRequestPruningPointUTXOSetAndBlock flow.
|
||||||
|
type HandleRequestPruningPointUTXOSetAndBlockContext interface {
|
||||||
|
Domain() domain.Domain
|
||||||
|
}
|
||||||
|
|
||||||
|
type handleRequestPruningPointUTXOSetAndBlockFlow struct {
|
||||||
|
HandleRequestPruningPointUTXOSetAndBlockContext
|
||||||
|
incomingRoute, outgoingRoute *router.Route
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleRequestPruningPointUTXOSetAndBlock listens to appmessage.MsgRequestPruningPointUTXOSetAndBlock messages and sends
|
||||||
|
// the pruning point UTXO set and block body.
|
||||||
|
func HandleRequestPruningPointUTXOSetAndBlock(context HandleRequestPruningPointUTXOSetAndBlockContext, incomingRoute,
|
||||||
|
outgoingRoute *router.Route) error {
|
||||||
|
flow := &handleRequestPruningPointUTXOSetAndBlockFlow{
|
||||||
|
HandleRequestPruningPointUTXOSetAndBlockContext: context,
|
||||||
|
incomingRoute: incomingRoute,
|
||||||
|
outgoingRoute: outgoingRoute,
|
||||||
|
}
|
||||||
|
|
||||||
|
return flow.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRequestPruningPointUTXOSetAndBlockFlow) start() error {
|
||||||
|
for {
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock, err := flow.waitForRequestPruningPointUTXOSetAndBlockMessages()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = flow.handleRequestPruningPointUTXOSetAndBlockMessage(msgRequestPruningPointUTXOSetAndBlock)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRequestPruningPointUTXOSetAndBlockFlow) handleRequestPruningPointUTXOSetAndBlockMessage(
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock *appmessage.MsgRequestPruningPointUTXOSetAndBlock) error {
|
||||||
|
|
||||||
|
onEnd := logger.LogAndMeasureExecutionTime(log, "handleRequestPruningPointUTXOSetAndBlockFlow")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
|
log.Debugf("Got request for PruningPointHash UTXOSet and Block")
|
||||||
|
|
||||||
|
err := flow.sendPruningPointBlock(msgRequestPruningPointUTXOSetAndBlock)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return flow.sendPruningPointUTXOSet(msgRequestPruningPointUTXOSetAndBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRequestPruningPointUTXOSetAndBlockFlow) waitForRequestPruningPointUTXOSetAndBlockMessages() (
|
||||||
|
*appmessage.MsgRequestPruningPointUTXOSetAndBlock, error) {
|
||||||
|
|
||||||
|
message, err := flow.incomingRoute.Dequeue()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock, ok := message.(*appmessage.MsgRequestPruningPointUTXOSetAndBlock)
|
||||||
|
if !ok {
|
||||||
|
return nil, protocolerrors.Errorf(true, "received unexpected message type. "+
|
||||||
|
"expected: %s, got: %s", appmessage.CmdRequestPruningPointUTXOSetAndBlock, message.Command())
|
||||||
|
}
|
||||||
|
return msgRequestPruningPointUTXOSetAndBlock, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRequestPruningPointUTXOSetAndBlockFlow) sendPruningPointBlock(
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock *appmessage.MsgRequestPruningPointUTXOSetAndBlock) error {
|
||||||
|
|
||||||
|
block, err := flow.Domain().Consensus().GetBlock(msgRequestPruningPointUTXOSetAndBlock.PruningPointHash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("Retrieved pruning block %s", msgRequestPruningPointUTXOSetAndBlock.PruningPointHash)
|
||||||
|
|
||||||
|
return flow.outgoingRoute.Enqueue(appmessage.NewMsgIBDBlock(appmessage.DomainBlockToMsgBlock(block)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRequestPruningPointUTXOSetAndBlockFlow) sendPruningPointUTXOSet(
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock *appmessage.MsgRequestPruningPointUTXOSetAndBlock) error {
|
||||||
|
|
||||||
|
// Send the UTXO set in `step`-sized chunks
|
||||||
|
const step = 1000
|
||||||
|
var fromOutpoint *externalapi.DomainOutpoint
|
||||||
|
chunksSent := 0
|
||||||
|
for {
|
||||||
|
pruningPointUTXOs, err := flow.Domain().Consensus().GetPruningPointUTXOs(
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock.PruningPointHash, fromOutpoint, step)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, ruleerrors.ErrWrongPruningPointHash) {
|
||||||
|
return flow.outgoingRoute.Enqueue(appmessage.NewMsgUnexpectedPruningPoint())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Retrieved %d UTXOs for pruning block %s",
|
||||||
|
len(pruningPointUTXOs), msgRequestPruningPointUTXOSetAndBlock.PruningPointHash)
|
||||||
|
|
||||||
|
outpointAndUTXOEntryPairs :=
|
||||||
|
appmessage.DomainOutpointAndUTXOEntryPairsToOutpointAndUTXOEntryPairs(pruningPointUTXOs)
|
||||||
|
err = flow.outgoingRoute.Enqueue(appmessage.NewMsgPruningPointUTXOSetChunk(outpointAndUTXOEntryPairs))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pruningPointUTXOs) < step {
|
||||||
|
log.Debugf("Finished sending UTXOs for pruning block %s",
|
||||||
|
msgRequestPruningPointUTXOSetAndBlock.PruningPointHash)
|
||||||
|
|
||||||
|
return flow.outgoingRoute.Enqueue(appmessage.NewMsgDonePruningPointUTXOSetChunks())
|
||||||
|
}
|
||||||
|
|
||||||
|
fromOutpoint = pruningPointUTXOs[len(pruningPointUTXOs)-1].Outpoint
|
||||||
|
chunksSent++
|
||||||
|
|
||||||
|
// Wait for the peer to request more chunks every `ibdBatchSize` chunks
|
||||||
|
if chunksSent%ibdBatchSize == 0 {
|
||||||
|
message, err := flow.incomingRoute.DequeueWithTimeout(common.DefaultTimeout)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, ok := message.(*appmessage.MsgRequestNextPruningPointUTXOSetChunk)
|
||||||
|
if !ok {
|
||||||
|
return protocolerrors.Errorf(true, "received unexpected message type. "+
|
||||||
|
"expected: %s, got: %s", appmessage.CmdRequestNextPruningPointUTXOSetChunk, message.Command())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package blockrelay
|
package blockrelay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/logger"
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
@@ -16,67 +17,78 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) error {
|
func (flow *handleRelayInvsFlow) runIBDIfNotRunning(highHash *externalapi.DomainHash) error {
|
||||||
wasIBDNotRunning := flow.TrySetIBDRunning(flow.peer)
|
wasIBDNotRunning := flow.TrySetIBDRunning(flow.peer)
|
||||||
if !wasIBDNotRunning {
|
if !wasIBDNotRunning {
|
||||||
log.Debugf("IBD is already running")
|
log.Debugf("IBD is already running")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
defer flow.UnsetIBDRunning()
|
||||||
|
|
||||||
isFinishedSuccessfully := false
|
|
||||||
defer func() {
|
|
||||||
flow.UnsetIBDRunning()
|
|
||||||
flow.logIBDFinished(isFinishedSuccessfully)
|
|
||||||
}()
|
|
||||||
|
|
||||||
highHash := consensushashing.BlockHash(block)
|
|
||||||
log.Debugf("IBD started with peer %s and highHash %s", flow.peer, highHash)
|
log.Debugf("IBD started with peer %s and highHash %s", flow.peer, highHash)
|
||||||
log.Debugf("Syncing blocks up to %s", highHash)
|
|
||||||
log.Debugf("Trying to find highest shared chain block with peer %s with high hash %s", flow.peer, highHash)
|
log.Debugf("Syncing headers up to %s", highHash)
|
||||||
highestSharedBlockHash, highestSharedBlockFound, err := flow.findHighestSharedBlockHash(highHash)
|
headersSynced, err := flow.syncHeaders(highHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("Found highest shared chain block %s with peer %s", highestSharedBlockHash, flow.peer)
|
if !headersSynced {
|
||||||
|
log.Debugf("Aborting IBD because the headers failed to sync")
|
||||||
shouldDownloadHeadersProof, shouldSync, err := flow.shouldSyncAndShouldDownloadHeadersProof(block, highestSharedBlockFound)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !shouldSync {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Debugf("Finished syncing headers up to %s", highHash)
|
||||||
|
|
||||||
if shouldDownloadHeadersProof {
|
log.Debugf("Syncing the current pruning point UTXO set")
|
||||||
log.Infof("Starting IBD with headers proof")
|
syncedPruningPointUTXOSetSuccessfully, err := flow.syncPruningPointUTXOSet()
|
||||||
err := flow.ibdWithHeadersProof(highHash)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = flow.syncPruningPointFutureHeaders(flow.Domain().Consensus(), highestSharedBlockHash, highHash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if !syncedPruningPointUTXOSetSuccessfully {
|
||||||
|
log.Debugf("Aborting IBD because the pruning point UTXO set failed to sync")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
log.Debugf("Finished syncing the current pruning point UTXO set")
|
||||||
|
|
||||||
|
log.Debugf("Downloading block bodies up to %s", highHash)
|
||||||
err = flow.syncMissingBlockBodies(highHash)
|
err = flow.syncMissingBlockBodies(highHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Debugf("Finished downloading block bodies up to %s", highHash)
|
||||||
|
|
||||||
log.Debugf("Finished syncing blocks up to %s", highHash)
|
|
||||||
isFinishedSuccessfully = true
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) logIBDFinished(isFinishedSuccessfully bool) {
|
// syncHeaders attempts to sync headers from the peer. This method may fail
|
||||||
successString := "successfully"
|
// because the peer and us have conflicting pruning points. In that case we
|
||||||
if !isFinishedSuccessfully {
|
// return (false, nil) so that we may stop IBD gracefully.
|
||||||
successString = "(interrupted)"
|
func (flow *handleRelayInvsFlow) syncHeaders(highHash *externalapi.DomainHash) (bool, error) {
|
||||||
|
log.Debugf("Trying to find highest shared chain block with peer %s with high hash %s", flow.peer, highHash)
|
||||||
|
highestSharedBlockHash, highestSharedBlockFound, err := flow.findHighestSharedBlockHash(highHash)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
}
|
}
|
||||||
log.Infof("IBD finished %s", successString)
|
if !highestSharedBlockFound {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
log.Debugf("Found highest shared chain block %s with peer %s", highestSharedBlockHash, flow.peer)
|
||||||
|
|
||||||
|
err = flow.downloadHeaders(highestSharedBlockHash, highHash)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the highHash has not been received, the peer is misbehaving
|
||||||
|
highHashBlockInfo, err := flow.Domain().Consensus().GetBlockInfo(highHash)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !highHashBlockInfo.Exists {
|
||||||
|
return false, protocolerrors.Errorf(true, "did not receive "+
|
||||||
|
"highHash header %s from peer %s during header download", highHash, flow.peer)
|
||||||
|
}
|
||||||
|
log.Debugf("Headers downloaded from peer %s", flow.peer)
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// findHighestSharedBlock attempts to find the highest shared block between the peer
|
// findHighestSharedBlock attempts to find the highest shared block between the peer
|
||||||
@@ -196,22 +208,20 @@ func (flow *handleRelayInvsFlow) fetchHighestHash(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) syncPruningPointFutureHeaders(consensus externalapi.Consensus, highestSharedBlockHash *externalapi.DomainHash,
|
func (flow *handleRelayInvsFlow) downloadHeaders(highestSharedBlockHash *externalapi.DomainHash,
|
||||||
highHash *externalapi.DomainHash) error {
|
highHash *externalapi.DomainHash) error {
|
||||||
|
|
||||||
log.Infof("Downloading headers from %s", flow.peer)
|
|
||||||
|
|
||||||
err := flow.sendRequestHeaders(highestSharedBlockHash, highHash)
|
err := flow.sendRequestHeaders(highestSharedBlockHash, highHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep a short queue of BlockHeadersMessages so that there's
|
// Keep a short queue of blockHeadersMessages so that there's
|
||||||
// never a moment when the node is not validating and inserting
|
// never a moment when the node is not validating and inserting
|
||||||
// headers
|
// headers
|
||||||
blockHeadersMessageChan := make(chan *appmessage.BlockHeadersMessage, 2)
|
blockHeadersMessageChan := make(chan *appmessage.BlockHeadersMessage, 2)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
spawn("handleRelayInvsFlow-syncPruningPointFutureHeaders", func() {
|
spawn("handleRelayInvsFlow-downloadHeaders", func() {
|
||||||
for {
|
for {
|
||||||
blockHeadersMessage, doneIBD, err := flow.receiveHeaders()
|
blockHeadersMessage, doneIBD, err := flow.receiveHeaders()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -235,21 +245,12 @@ func (flow *handleRelayInvsFlow) syncPruningPointFutureHeaders(consensus externa
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ibdBlocksMessage, ok := <-blockHeadersMessageChan:
|
case blockHeadersMessage, ok := <-blockHeadersMessageChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
// If the highHash has not been received, the peer is misbehaving
|
|
||||||
highHashBlockInfo, err := consensus.GetBlockInfo(highHash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !highHashBlockInfo.Exists {
|
|
||||||
return protocolerrors.Errorf(true, "did not receive "+
|
|
||||||
"highHash block %s from peer %s during block download", highHash, flow.peer)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, header := range ibdBlocksMessage.BlockHeaders {
|
for _, header := range blockHeadersMessage.BlockHeaders {
|
||||||
err = flow.processHeader(consensus, header)
|
err = flow.processHeader(header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -267,7 +268,7 @@ func (flow *handleRelayInvsFlow) sendRequestHeaders(highestSharedBlockHash *exte
|
|||||||
return flow.outgoingRoute.Enqueue(msgGetBlockInvs)
|
return flow.outgoingRoute.Enqueue(msgGetBlockInvs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) receiveHeaders() (msgIBDBlock *appmessage.BlockHeadersMessage, doneHeaders bool, err error) {
|
func (flow *handleRelayInvsFlow) receiveHeaders() (msgIBDBlock *appmessage.BlockHeadersMessage, doneIBD bool, err error) {
|
||||||
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
@@ -280,14 +281,11 @@ func (flow *handleRelayInvsFlow) receiveHeaders() (msgIBDBlock *appmessage.Block
|
|||||||
default:
|
default:
|
||||||
return nil, false,
|
return nil, false,
|
||||||
protocolerrors.Errorf(true, "received unexpected message type. "+
|
protocolerrors.Errorf(true, "received unexpected message type. "+
|
||||||
"expected: %s or %s, got: %s",
|
"expected: %s or %s, got: %s", appmessage.CmdHeader, appmessage.CmdDoneHeaders, message.Command())
|
||||||
appmessage.CmdBlockHeaders,
|
|
||||||
appmessage.CmdDoneHeaders,
|
|
||||||
message.Command())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) processHeader(consensus externalapi.Consensus, msgBlockHeader *appmessage.MsgBlockHeader) error {
|
func (flow *handleRelayInvsFlow) processHeader(msgBlockHeader *appmessage.MsgBlockHeader) error {
|
||||||
header := appmessage.BlockHeaderToDomainBlockHeader(msgBlockHeader)
|
header := appmessage.BlockHeaderToDomainBlockHeader(msgBlockHeader)
|
||||||
block := &externalapi.DomainBlock{
|
block := &externalapi.DomainBlock{
|
||||||
Header: header,
|
Header: header,
|
||||||
@@ -295,7 +293,7 @@ func (flow *handleRelayInvsFlow) processHeader(consensus externalapi.Consensus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockHash := consensushashing.BlockHash(block)
|
blockHash := consensushashing.BlockHash(block)
|
||||||
blockInfo, err := consensus.GetBlockInfo(blockHash)
|
blockInfo, err := flow.Domain().Consensus().GetBlockInfo(blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -303,7 +301,7 @@ func (flow *handleRelayInvsFlow) processHeader(consensus externalapi.Consensus,
|
|||||||
log.Debugf("Block header %s is already in the DAG. Skipping...", blockHash)
|
log.Debugf("Block header %s is already in the DAG. Skipping...", blockHash)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, err = consensus.ValidateAndInsertBlock(block, false)
|
_, err = flow.Domain().Consensus().ValidateAndInsertBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.As(err, &ruleerrors.RuleError{}) {
|
if !errors.As(err, &ruleerrors.RuleError{}) {
|
||||||
return errors.Wrapf(err, "failed to process header %s during IBD", blockHash)
|
return errors.Wrapf(err, "failed to process header %s during IBD", blockHash)
|
||||||
@@ -320,42 +318,129 @@ func (flow *handleRelayInvsFlow) processHeader(consensus externalapi.Consensus,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) validatePruningPointFutureHeaderTimestamps() error {
|
func (flow *handleRelayInvsFlow) syncPruningPointUTXOSet() (bool, error) {
|
||||||
headerSelectedTipHash, err := flow.Domain().StagingConsensus().GetHeadersSelectedTip()
|
log.Debugf("Checking if a new pruning point is available")
|
||||||
|
err := flow.outgoingRoute.Enqueue(appmessage.NewMsgRequestPruningPointHashMessage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
headerSelectedTipHeader, err := flow.Domain().StagingConsensus().GetBlockHeader(headerSelectedTipHash)
|
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
headerSelectedTipTimestamp := headerSelectedTipHeader.TimeInMilliseconds()
|
msgPruningPointHash, ok := message.(*appmessage.MsgPruningPointHashMessage)
|
||||||
|
if !ok {
|
||||||
currentSelectedTipHash, err := flow.Domain().Consensus().GetHeadersSelectedTip()
|
return false, protocolerrors.Errorf(true, "received unexpected message type. "+
|
||||||
if err != nil {
|
"expected: %s, got: %s", appmessage.CmdPruningPointHash, message.Command())
|
||||||
return err
|
|
||||||
}
|
|
||||||
currentSelectedTipHeader, err := flow.Domain().Consensus().GetBlockHeader(currentSelectedTipHash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
currentSelectedTipTimestamp := currentSelectedTipHeader.TimeInMilliseconds()
|
|
||||||
|
|
||||||
if headerSelectedTipTimestamp < currentSelectedTipTimestamp {
|
|
||||||
return protocolerrors.Errorf(false, "the timestamp of the candidate selected "+
|
|
||||||
"tip is smaller than the current selected tip")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
minTimestampDifferenceInMilliseconds := (10 * time.Minute).Milliseconds()
|
blockInfo, err := flow.Domain().Consensus().GetBlockInfo(msgPruningPointHash.Hash)
|
||||||
if headerSelectedTipTimestamp-currentSelectedTipTimestamp < minTimestampDifferenceInMilliseconds {
|
if err != nil {
|
||||||
return protocolerrors.Errorf(false, "difference between the timestamps of "+
|
return false, err
|
||||||
"the current pruning point and the candidate pruning point is too small. Aborting IBD...")
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
if !blockInfo.Exists {
|
||||||
|
return false, errors.Errorf("The pruning point header is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if blockInfo.BlockStatus != externalapi.StatusHeaderOnly {
|
||||||
|
log.Debugf("Already has the block data of the new suggested pruning point %s", msgPruningPointHash.Hash)
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Checking if the suggested pruning point %s is compatible to the node DAG", msgPruningPointHash.Hash)
|
||||||
|
isValid, err := flow.Domain().Consensus().IsValidPruningPoint(msgPruningPointHash.Hash)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isValid {
|
||||||
|
log.Infof("The suggested pruning point %s is incompatible to this node DAG, so stopping IBD with this"+
|
||||||
|
" peer", msgPruningPointHash.Hash)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Fetching the pruning point UTXO set")
|
||||||
|
succeed, err := flow.fetchMissingUTXOSet(msgPruningPointHash.Hash)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !succeed {
|
||||||
|
log.Infof("Couldn't successfully fetch the pruning point UTXO set. Stopping IBD.")
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Fetched the new pruning point UTXO set")
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRelayInvsFlow) fetchMissingUTXOSet(pruningPointHash *externalapi.DomainHash) (succeed bool, err error) {
|
||||||
|
defer func() {
|
||||||
|
err := flow.Domain().Consensus().ClearImportedPruningPointData()
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to clear imported pruning point data: %s", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = flow.outgoingRoute.Enqueue(appmessage.NewMsgRequestPruningPointUTXOSetAndBlock(pruningPointHash))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := flow.receivePruningPointBlock()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
receivedAll, err := flow.receiveAndInsertPruningPointUTXOSet(pruningPointHash)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !receivedAll {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = flow.Domain().Consensus().ValidateAndInsertImportedPruningPoint(block)
|
||||||
|
if err != nil {
|
||||||
|
// TODO: Find a better way to deal with finality conflicts.
|
||||||
|
if errors.Is(err, ruleerrors.ErrSuggestedPruningViolatesFinality) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, protocolerrors.ConvertToBanningProtocolErrorIfRuleError(err, "error with pruning point UTXO set")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = flow.OnPruningPointUTXOSetOverride()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (flow *handleRelayInvsFlow) receivePruningPointBlock() (*externalapi.DomainBlock, error) {
|
||||||
|
onEnd := logger.LogAndMeasureExecutionTime(log, "receivePruningPointBlock")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
|
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ibdBlockMessage, ok := message.(*appmessage.MsgIBDBlock)
|
||||||
|
if !ok {
|
||||||
|
return nil, protocolerrors.Errorf(true, "received unexpected message type. "+
|
||||||
|
"expected: %s, got: %s", appmessage.CmdIBDBlock, message.Command())
|
||||||
|
}
|
||||||
|
block := appmessage.MsgBlockToDomainBlock(ibdBlockMessage.MsgBlock)
|
||||||
|
|
||||||
|
log.Debugf("Received pruning point block %s", consensushashing.BlockHash(block))
|
||||||
|
|
||||||
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) receiveAndInsertPruningPointUTXOSet(
|
func (flow *handleRelayInvsFlow) receiveAndInsertPruningPointUTXOSet(
|
||||||
consensus externalapi.Consensus, pruningPointHash *externalapi.DomainHash) (bool, error) {
|
pruningPointHash *externalapi.DomainHash) (bool, error) {
|
||||||
|
|
||||||
onEnd := logger.LogAndMeasureExecutionTime(log, "receiveAndInsertPruningPointUTXOSet")
|
onEnd := logger.LogAndMeasureExecutionTime(log, "receiveAndInsertPruningPointUTXOSet")
|
||||||
defer onEnd()
|
defer onEnd()
|
||||||
@@ -374,7 +459,7 @@ func (flow *handleRelayInvsFlow) receiveAndInsertPruningPointUTXOSet(
|
|||||||
domainOutpointAndUTXOEntryPairs :=
|
domainOutpointAndUTXOEntryPairs :=
|
||||||
appmessage.OutpointAndUTXOEntryPairsToDomainOutpointAndUTXOEntryPairs(message.OutpointAndUTXOEntryPairs)
|
appmessage.OutpointAndUTXOEntryPairsToDomainOutpointAndUTXOEntryPairs(message.OutpointAndUTXOEntryPairs)
|
||||||
|
|
||||||
err := consensus.AppendImportedPruningPointUTXOs(domainOutpointAndUTXOEntryPairs)
|
err := flow.Domain().Consensus().AppendImportedPruningPointUTXOs(domainOutpointAndUTXOEntryPairs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -458,7 +543,7 @@ func (flow *handleRelayInvsFlow) syncMissingBlockBodies(highHash *externalapi.Do
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
blockInsertionResult, err := flow.Domain().Consensus().ValidateAndInsertBlock(block, false)
|
blockInsertionResult, err := flow.Domain().Consensus().ValidateAndInsertBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ruleerrors.ErrDuplicateBlock) {
|
if errors.Is(err, ruleerrors.ErrDuplicateBlock) {
|
||||||
log.Debugf("Skipping IBD Block %s as it has already been added to the DAG", blockHash)
|
log.Debugf("Skipping IBD Block %s as it has already been added to the DAG", blockHash)
|
||||||
@@ -473,7 +558,7 @@ func (flow *handleRelayInvsFlow) syncMissingBlockBodies(highHash *externalapi.Do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flow.Domain().Consensus().ResolveVirtual()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// dequeueIncomingMessageAndSkipInvs is a convenience method to be used during
|
// dequeueIncomingMessageAndSkipInvs is a convenience method to be used during
|
||||||
|
|||||||
@@ -1,364 +0,0 @@
|
|||||||
package blockrelay
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/common"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) ibdWithHeadersProof(highHash *externalapi.DomainHash) error {
|
|
||||||
err := flow.Domain().InitStagingConsensus()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.downloadHeadersAndPruningUTXOSet(highHash)
|
|
||||||
if err != nil {
|
|
||||||
if !flow.IsRecoverableError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteStagingConsensusErr := flow.Domain().DeleteStagingConsensus()
|
|
||||||
if deleteStagingConsensusErr != nil {
|
|
||||||
return deleteStagingConsensusErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.Domain().CommitStagingConsensus()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) shouldSyncAndShouldDownloadHeadersProof(highBlock *externalapi.DomainBlock,
|
|
||||||
highestSharedBlockFound bool) (shouldDownload, shouldSync bool, err error) {
|
|
||||||
|
|
||||||
if !highestSharedBlockFound {
|
|
||||||
hasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore, err := flow.checkIfHighHashHasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore(highBlock)
|
|
||||||
if err != nil {
|
|
||||||
return false, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if hasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore {
|
|
||||||
return true, true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) checkIfHighHashHasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore(highBlock *externalapi.DomainBlock) (bool, error) {
|
|
||||||
headersSelectedTip, err := flow.Domain().Consensus().GetHeadersSelectedTip()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
headersSelectedTipInfo, err := flow.Domain().Consensus().GetBlockInfo(headersSelectedTip)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if highBlock.Header.BlueScore() < headersSelectedTipInfo.BlueScore+flow.Config().NetParams().PruningDepth() {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return highBlock.Header.BlueWork().Cmp(headersSelectedTipInfo.BlueWork) > 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) syncAndValidatePruningPointProof() (*externalapi.DomainHash, error) {
|
|
||||||
log.Infof("Downloading the pruning point proof from %s", flow.peer)
|
|
||||||
err := flow.outgoingRoute.Enqueue(appmessage.NewMsgRequestPruningPointProof())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pruningPointProofMessage, ok := message.(*appmessage.MsgPruningPointProof)
|
|
||||||
if !ok {
|
|
||||||
return nil, protocolerrors.Errorf(true, "received unexpected message type. "+
|
|
||||||
"expected: %s, got: %s", appmessage.CmdPruningPointProof, message.Command())
|
|
||||||
}
|
|
||||||
pruningPointProof := appmessage.MsgPruningPointProofToDomainPruningPointProof(pruningPointProofMessage)
|
|
||||||
err = flow.Domain().Consensus().ValidatePruningPointProof(pruningPointProof)
|
|
||||||
if err != nil {
|
|
||||||
if errors.As(err, &ruleerrors.RuleError{}) {
|
|
||||||
return nil, protocolerrors.Wrapf(true, err, "pruning point proof validation failed")
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.Domain().StagingConsensus().ApplyPruningPointProof(pruningPointProof)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return consensushashing.HeaderHash(pruningPointProof.Headers[0][len(pruningPointProof.Headers[0])-1]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) downloadHeadersAndPruningUTXOSet(highHash *externalapi.DomainHash) error {
|
|
||||||
proofPruningPoint, err := flow.syncAndValidatePruningPointProof()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.syncPruningPointsAndPruningPointAnticone(proofPruningPoint)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove this condition once there's more proper way to check finality violation
|
|
||||||
// in the headers proof.
|
|
||||||
if proofPruningPoint.Equal(flow.Config().NetParams().GenesisHash) {
|
|
||||||
return protocolerrors.Errorf(true, "the genesis pruning point violates finality")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.syncPruningPointFutureHeaders(flow.Domain().StagingConsensus(), proofPruningPoint, highHash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Headers downloaded from peer %s", flow.peer)
|
|
||||||
|
|
||||||
highHashInfo, err := flow.Domain().StagingConsensus().GetBlockInfo(highHash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !highHashInfo.Exists {
|
|
||||||
return protocolerrors.Errorf(true, "the triggering IBD block was not sent")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.validatePruningPointFutureHeaderTimestamps()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Syncing the current pruning point UTXO set")
|
|
||||||
syncedPruningPointUTXOSetSuccessfully, err := flow.syncPruningPointUTXOSet(flow.Domain().StagingConsensus(), proofPruningPoint)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !syncedPruningPointUTXOSetSuccessfully {
|
|
||||||
log.Debugf("Aborting IBD because the pruning point UTXO set failed to sync")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
log.Debugf("Finished syncing the current pruning point UTXO set")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) syncPruningPointsAndPruningPointAnticone(proofPruningPoint *externalapi.DomainHash) error {
|
|
||||||
log.Infof("Downloading the past pruning points and the pruning point anticone from %s", flow.peer)
|
|
||||||
err := flow.outgoingRoute.Enqueue(appmessage.NewMsgRequestPruningPointAndItsAnticone())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.validateAndInsertPruningPoints(proofPruningPoint)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pruningPointWithMetaData, done, err := flow.receiveBlockWithTrustedData()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if done {
|
|
||||||
return protocolerrors.Errorf(true, "got `done` message before receiving the pruning point")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !pruningPointWithMetaData.Block.Header.BlockHash().Equal(proofPruningPoint) {
|
|
||||||
return protocolerrors.Errorf(true, "first block with trusted data is not the pruning point")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.processBlockWithTrustedData(flow.Domain().StagingConsensus(), pruningPointWithMetaData)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
blockWithTrustedData, done, err := flow.receiveBlockWithTrustedData()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if done {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.processBlockWithTrustedData(flow.Domain().StagingConsensus(), blockWithTrustedData)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Finished downloading pruning point and its anticone from %s", flow.peer)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) processBlockWithTrustedData(
|
|
||||||
consensus externalapi.Consensus, block *appmessage.MsgBlockWithTrustedData) error {
|
|
||||||
|
|
||||||
_, err := consensus.ValidateAndInsertBlockWithTrustedData(appmessage.BlockWithTrustedDataToDomainBlockWithTrustedData(block), false)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) receiveBlockWithTrustedData() (*appmessage.MsgBlockWithTrustedData, bool, error) {
|
|
||||||
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch downCastedMessage := message.(type) {
|
|
||||||
case *appmessage.MsgBlockWithTrustedData:
|
|
||||||
return downCastedMessage, false, nil
|
|
||||||
case *appmessage.MsgDoneBlocksWithTrustedData:
|
|
||||||
return nil, true, nil
|
|
||||||
default:
|
|
||||||
return nil, false,
|
|
||||||
protocolerrors.Errorf(true, "received unexpected message type. "+
|
|
||||||
"expected: %s or %s, got: %s",
|
|
||||||
(&appmessage.MsgBlockWithTrustedData{}).Command(),
|
|
||||||
(&appmessage.MsgDoneBlocksWithTrustedData{}).Command(),
|
|
||||||
downCastedMessage.Command())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) receivePruningPoints() (*appmessage.MsgPruningPoints, error) {
|
|
||||||
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msgPruningPoints, ok := message.(*appmessage.MsgPruningPoints)
|
|
||||||
if !ok {
|
|
||||||
return nil,
|
|
||||||
protocolerrors.Errorf(true, "received unexpected message type. "+
|
|
||||||
"expected: %s, got: %s", appmessage.CmdPruningPoints, message.Command())
|
|
||||||
}
|
|
||||||
|
|
||||||
return msgPruningPoints, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) validateAndInsertPruningPoints(proofPruningPoint *externalapi.DomainHash) error {
|
|
||||||
currentPruningPoint, err := flow.Domain().Consensus().PruningPoint()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentPruningPoint.Equal(proofPruningPoint) {
|
|
||||||
return protocolerrors.Errorf(true, "the proposed pruning point is the same as the current pruning point")
|
|
||||||
}
|
|
||||||
|
|
||||||
pruningPoints, err := flow.receivePruningPoints()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
headers := make([]externalapi.BlockHeader, len(pruningPoints.Headers))
|
|
||||||
for i, header := range pruningPoints.Headers {
|
|
||||||
headers[i] = appmessage.BlockHeaderToDomainBlockHeader(header)
|
|
||||||
}
|
|
||||||
|
|
||||||
arePruningPointsViolatingFinality, err := flow.Domain().Consensus().ArePruningPointsViolatingFinality(headers)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if arePruningPointsViolatingFinality {
|
|
||||||
// TODO: Find a better way to deal with finality conflicts.
|
|
||||||
return protocolerrors.Errorf(false, "pruning points are violating finality")
|
|
||||||
}
|
|
||||||
|
|
||||||
lastPruningPoint := consensushashing.HeaderHash(headers[len(headers)-1])
|
|
||||||
if !lastPruningPoint.Equal(proofPruningPoint) {
|
|
||||||
return protocolerrors.Errorf(true, "the proof pruning point is not equal to the last pruning "+
|
|
||||||
"point in the list")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.Domain().StagingConsensus().ImportPruningPoints(headers)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) syncPruningPointUTXOSet(consensus externalapi.Consensus,
|
|
||||||
pruningPoint *externalapi.DomainHash) (bool, error) {
|
|
||||||
|
|
||||||
log.Infof("Checking if the suggested pruning point %s is compatible to the node DAG", pruningPoint)
|
|
||||||
isValid, err := flow.Domain().StagingConsensus().IsValidPruningPoint(pruningPoint)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isValid {
|
|
||||||
return false, protocolerrors.Errorf(true, "invalid pruning point %s", pruningPoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Fetching the pruning point UTXO set")
|
|
||||||
isSuccessful, err := flow.fetchMissingUTXOSet(consensus, pruningPoint)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isSuccessful {
|
|
||||||
log.Infof("Couldn't successfully fetch the pruning point UTXO set. Stopping IBD.")
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Fetched the new pruning point UTXO set")
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) fetchMissingUTXOSet(consensus externalapi.Consensus, pruningPointHash *externalapi.DomainHash) (succeed bool, err error) {
|
|
||||||
defer func() {
|
|
||||||
err := flow.Domain().StagingConsensus().ClearImportedPruningPointData()
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("failed to clear imported pruning point data: %s", err))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
err = flow.outgoingRoute.Enqueue(appmessage.NewMsgRequestPruningPointUTXOSet(pruningPointHash))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
receivedAll, err := flow.receiveAndInsertPruningPointUTXOSet(consensus, pruningPointHash)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
if !receivedAll {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.Domain().StagingConsensus().ValidateAndInsertImportedPruningPoint(pruningPointHash)
|
|
||||||
if err != nil {
|
|
||||||
// TODO: Find a better way to deal with finality conflicts.
|
|
||||||
if errors.Is(err, ruleerrors.ErrSuggestedPruningViolatesFinality) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, protocolerrors.ConvertToBanningProtocolErrorIfRuleError(err, "error with pruning point UTXO set")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = flow.OnPruningPointUTXOSetOverride()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
@@ -4,14 +4,12 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
"github.com/kaspanet/kaspad/domain"
|
"github.com/kaspanet/kaspad/domain"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendVirtualSelectedParentInvContext is the interface for the context needed for the SendVirtualSelectedParentInv flow.
|
// SendVirtualSelectedParentInvContext is the interface for the context needed for the SendVirtualSelectedParentInv flow.
|
||||||
type SendVirtualSelectedParentInvContext interface {
|
type SendVirtualSelectedParentInvContext interface {
|
||||||
Domain() domain.Domain
|
Domain() domain.Domain
|
||||||
Config() *config.Config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendVirtualSelectedParentInv sends a peer the selected parent hash of the virtual
|
// SendVirtualSelectedParentInv sends a peer the selected parent hash of the virtual
|
||||||
@@ -23,11 +21,6 @@ func SendVirtualSelectedParentInv(context SendVirtualSelectedParentInvContext,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if virtualSelectedParent.Equal(context.Config().NetParams().GenesisHash) {
|
|
||||||
log.Debugf("Skipping sending the virtual selected parent hash to peer %s because it's the genesis", peer)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Sending virtual selected parent hash %s to peer %s", virtualSelectedParent, peer)
|
log.Debugf("Sending virtual selected parent hash %s to peer %s", virtualSelectedParent, peer)
|
||||||
|
|
||||||
virtualSelectedParentInv := appmessage.NewMsgInvBlock(virtualSelectedParent)
|
virtualSelectedParentInv := appmessage.NewMsgInvBlock(virtualSelectedParent)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
// SendPingsContext is the interface for the context needed for the SendPings flow.
|
// SendPingsContext is the interface for the context needed for the SendPings flow.
|
||||||
type SendPingsContext interface {
|
type SendPingsContext interface {
|
||||||
ShutdownChan() <-chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type sendPingsFlow struct {
|
type sendPingsFlow struct {
|
||||||
@@ -40,13 +39,7 @@ func (flow *sendPingsFlow) start() error {
|
|||||||
ticker := time.NewTicker(pingInterval)
|
ticker := time.NewTicker(pingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for range ticker.C {
|
||||||
select {
|
|
||||||
case <-flow.ShutdownChan():
|
|
||||||
return nil
|
|
||||||
case <-ticker.C:
|
|
||||||
}
|
|
||||||
|
|
||||||
nonce, err := random.Uint64()
|
nonce, err := random.Uint64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -69,4 +62,5 @@ func (flow *sendPingsFlow) start() error {
|
|||||||
}
|
}
|
||||||
flow.peer.SetPingIdle()
|
flow.peer.SetPingIdle()
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,5 +33,10 @@ func (flow *handleRejectsFlow) start() error {
|
|||||||
}
|
}
|
||||||
rejectMessage := message.(*appmessage.MsgReject)
|
rejectMessage := message.(*appmessage.MsgReject)
|
||||||
|
|
||||||
|
const maxReasonLength = 255
|
||||||
|
if len(rejectMessage.Reason) > maxReasonLength {
|
||||||
|
return protocolerrors.Errorf(false, "got reject message longer than %d", maxReasonLength)
|
||||||
|
}
|
||||||
|
|
||||||
return protocolerrors.Errorf(false, "got reject message: `%s`", rejectMessage.Reason)
|
return protocolerrors.Errorf(false, "got reject message: `%s`", rejectMessage.Reason)
|
||||||
}
|
}
|
||||||
|
|||||||
1562
app/protocol/flows/testing/handle_relay_invs_test.go
Normal file
1562
app/protocol/flows/testing/handle_relay_invs_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,15 @@
|
|||||||
package testing
|
package testing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/addressexchange"
|
"github.com/kaspanet/kaspad/app/protocol/flows/addressexchange"
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
||||||
|
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeReceiveAddressesContext struct{}
|
type fakeReceiveAddressesContext struct{}
|
||||||
@@ -20,9 +19,9 @@ func (f fakeReceiveAddressesContext) AddressManager() *addressmanager.AddressMan
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReceiveAddressesErrors(t *testing.T) {
|
func TestReceiveAddressesErrors(t *testing.T) {
|
||||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
testutils.ForAllNets(t, true, func(t *testing.T, params *dagconfig.Params) {
|
||||||
incomingRoute := router.NewRoute("incoming")
|
incomingRoute := router.NewRoute()
|
||||||
outgoingRoute := router.NewRoute("outgoing")
|
outgoingRoute := router.NewRoute()
|
||||||
peer := peerpkg.New(nil)
|
peer := peerpkg.New(nil)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ type TransactionsRelayContext interface {
|
|||||||
NetAdapter() *netadapter.NetAdapter
|
NetAdapter() *netadapter.NetAdapter
|
||||||
Domain() domain.Domain
|
Domain() domain.Domain
|
||||||
SharedRequestedTransactions() *SharedRequestedTransactions
|
SharedRequestedTransactions() *SharedRequestedTransactions
|
||||||
|
Broadcast(message appmessage.Message) error
|
||||||
OnTransactionAddedToMempool()
|
OnTransactionAddedToMempool()
|
||||||
EnqueueTransactionIDsForPropagation(transactionIDs []*externalapi.DomainTransactionID) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type handleRelayedTransactionsFlow struct {
|
type handleRelayedTransactionsFlow struct {
|
||||||
@@ -119,7 +119,8 @@ func (flow *handleRelayedTransactionsFlow) readInv() (*appmessage.MsgInvTransact
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleRelayedTransactionsFlow) broadcastAcceptedTransactions(acceptedTxIDs []*externalapi.DomainTransactionID) error {
|
func (flow *handleRelayedTransactionsFlow) broadcastAcceptedTransactions(acceptedTxIDs []*externalapi.DomainTransactionID) error {
|
||||||
return flow.EnqueueTransactionIDsForPropagation(acceptedTxIDs)
|
inv := appmessage.NewMsgInvTransaction(acceptedTxIDs)
|
||||||
|
return flow.Broadcast(inv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// readMsgTxOrNotFound returns the next msgTx or msgTransactionNotFound in incomingRoute,
|
// readMsgTxOrNotFound returns the next msgTx or msgTransactionNotFound in incomingRoute,
|
||||||
@@ -172,18 +173,17 @@ func (flow *handleRelayedTransactionsFlow) receiveTransactions(requestedTransact
|
|||||||
expectedID, txID)
|
expectedID, txID)
|
||||||
}
|
}
|
||||||
|
|
||||||
acceptedTransactions, err :=
|
err = flow.Domain().MiningManager().ValidateAndInsertTransaction(tx, true)
|
||||||
flow.Domain().MiningManager().ValidateAndInsertTransaction(tx, false, true)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ruleErr := &mempool.RuleError{}
|
ruleErr := &mempool.RuleError{}
|
||||||
if !errors.As(err, ruleErr) {
|
if !errors.As(err, ruleErr) {
|
||||||
return errors.Wrapf(err, "failed to process transaction %s", txID)
|
return errors.Wrapf(err, "failed to process transaction %s", txID)
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldBan := false
|
shouldBan := true
|
||||||
if txRuleErr := (&mempool.TxRuleError{}); errors.As(ruleErr.Err, txRuleErr) {
|
if txRuleErr := (&mempool.TxRuleError{}); errors.As(ruleErr.Err, txRuleErr) {
|
||||||
if txRuleErr.RejectCode == mempool.RejectInvalid {
|
if txRuleErr.RejectCode != mempool.RejectInvalid {
|
||||||
shouldBan = true
|
shouldBan = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ func (flow *handleRelayedTransactionsFlow) receiveTransactions(requestedTransact
|
|||||||
|
|
||||||
return protocolerrors.Errorf(true, "rejected transaction %s: %s", txID, ruleErr)
|
return protocolerrors.Errorf(true, "rejected transaction %s: %s", txID, ruleErr)
|
||||||
}
|
}
|
||||||
err = flow.broadcastAcceptedTransactions(consensushashing.TransactionIDs(acceptedTransactions))
|
err = flow.broadcastAcceptedTransactions([]*externalapi.DomainTransactionID{txID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,191 +0,0 @@
|
|||||||
package transactionrelay_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/transactionrelay"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/logger"
|
|
||||||
"github.com/kaspanet/kaspad/util/panics"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
)
|
|
||||||
|
|
||||||
type mocTransactionsRelayContext struct {
|
|
||||||
netAdapter *netadapter.NetAdapter
|
|
||||||
domain domain.Domain
|
|
||||||
sharedRequestedTransactions *transactionrelay.SharedRequestedTransactions
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mocTransactionsRelayContext) NetAdapter() *netadapter.NetAdapter {
|
|
||||||
return m.netAdapter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mocTransactionsRelayContext) Domain() domain.Domain {
|
|
||||||
return m.domain
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mocTransactionsRelayContext) SharedRequestedTransactions() *transactionrelay.SharedRequestedTransactions {
|
|
||||||
return m.sharedRequestedTransactions
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mocTransactionsRelayContext) EnqueueTransactionIDsForPropagation(transactionIDs []*externalapi.DomainTransactionID) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mocTransactionsRelayContext) OnTransactionAddedToMempool() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestHandleRelayedTransactionsNotFound tests the flow of HandleRelayedTransactions when the peer doesn't
|
|
||||||
// have the requested transactions in the mempool.
|
|
||||||
func TestHandleRelayedTransactionsNotFound(t *testing.T) {
|
|
||||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
|
||||||
|
|
||||||
var log = logger.RegisterSubSystem("PROT")
|
|
||||||
var spawn = panics.GoroutineWrapperFunc(log)
|
|
||||||
factory := consensus.NewFactory()
|
|
||||||
tc, teardown, err := factory.NewTestConsensus(consensusConfig, "TestHandleRelayedTransactionsNotFound")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error setting up test consensus: %+v", err)
|
|
||||||
}
|
|
||||||
defer teardown(false)
|
|
||||||
|
|
||||||
sharedRequestedTransactions := transactionrelay.NewSharedRequestedTransactions()
|
|
||||||
adapter, err := netadapter.NewNetAdapter(config.DefaultConfig())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to create a NetAdapter: %v", err)
|
|
||||||
}
|
|
||||||
domainInstance, err := domain.New(consensusConfig, mempool.DefaultConfig(&consensusConfig.Params), tc.Database())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to set up a domain instance: %v", err)
|
|
||||||
}
|
|
||||||
context := &mocTransactionsRelayContext{
|
|
||||||
netAdapter: adapter,
|
|
||||||
domain: domainInstance,
|
|
||||||
sharedRequestedTransactions: sharedRequestedTransactions,
|
|
||||||
}
|
|
||||||
incomingRoute := router.NewRoute("incoming")
|
|
||||||
defer incomingRoute.Close()
|
|
||||||
peerIncomingRoute := router.NewRoute("outgoing")
|
|
||||||
defer peerIncomingRoute.Close()
|
|
||||||
|
|
||||||
txID1 := externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})
|
|
||||||
txID2 := externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02})
|
|
||||||
txIDs := []*externalapi.DomainTransactionID{txID1, txID2}
|
|
||||||
invMessage := appmessage.NewMsgInvTransaction(txIDs)
|
|
||||||
err = incomingRoute.Enqueue(invMessage)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error from incomingRoute.Enqueue: %v", err)
|
|
||||||
}
|
|
||||||
// The goroutine is representing the peer's actions.
|
|
||||||
spawn("peerResponseToTheTransactionsRequest", func() {
|
|
||||||
msg, err := peerIncomingRoute.Dequeue()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Dequeue: %v", err)
|
|
||||||
}
|
|
||||||
inv := msg.(*appmessage.MsgRequestTransactions)
|
|
||||||
|
|
||||||
if len(txIDs) != len(inv.IDs) {
|
|
||||||
t.Fatalf("TestHandleRelayedTransactions: expected %d transactions ID, but got %d", len(txIDs), len(inv.IDs))
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, id := range inv.IDs {
|
|
||||||
if txIDs[i].String() != id.String() {
|
|
||||||
t.Fatalf("TestHandleRelayedTransactions: expected equal txID: expected %s, but got %s", txIDs[i].String(), id.String())
|
|
||||||
}
|
|
||||||
err = incomingRoute.Enqueue(appmessage.NewMsgTransactionNotFound(txIDs[i]))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error from incomingRoute.Enqueue: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Insert an unexpected message type to stop the infinity loop.
|
|
||||||
err = incomingRoute.Enqueue(&appmessage.MsgAddresses{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error from incomingRoute.Enqueue: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
err = transactionrelay.HandleRelayedTransactions(context, incomingRoute, peerIncomingRoute)
|
|
||||||
// Since we inserted an unexpected message type to stop the infinity loop,
|
|
||||||
// we expect the error will be infected from this specific message and also the
|
|
||||||
// error will count as a protocol message.
|
|
||||||
if protocolErr := (protocolerrors.ProtocolError{}); err == nil || !errors.As(err, &protocolErr) {
|
|
||||||
t.Fatalf("Expected to protocol error")
|
|
||||||
} else {
|
|
||||||
if !protocolErr.ShouldBan {
|
|
||||||
t.Fatalf("Exepcted shouldBan true, but got false.")
|
|
||||||
}
|
|
||||||
if !strings.Contains(err.Error(), "unexpected Addresses [code 3] message in the block relay flow while expecting an inv message") {
|
|
||||||
t.Fatalf("Unexpected error: expected: an error due to existence of an Addresses message "+
|
|
||||||
"in the block relay flow, but got: %v", protocolErr.Cause)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestOnClosedIncomingRoute verifies that an appropriate error message will be returned when
|
|
||||||
// trying to dequeue a message from a closed route.
|
|
||||||
func TestOnClosedIncomingRoute(t *testing.T) {
|
|
||||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
|
||||||
|
|
||||||
factory := consensus.NewFactory()
|
|
||||||
tc, teardown, err := factory.NewTestConsensus(consensusConfig, "TestOnClosedIncomingRoute")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error setting up test consensus: %+v", err)
|
|
||||||
}
|
|
||||||
defer teardown(false)
|
|
||||||
|
|
||||||
sharedRequestedTransactions := transactionrelay.NewSharedRequestedTransactions()
|
|
||||||
adapter, err := netadapter.NewNetAdapter(config.DefaultConfig())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to creat a NetAdapter : %v", err)
|
|
||||||
}
|
|
||||||
domainInstance, err := domain.New(consensusConfig, mempool.DefaultConfig(&consensusConfig.Params), tc.Database())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to set up a domain instance: %v", err)
|
|
||||||
}
|
|
||||||
context := &mocTransactionsRelayContext{
|
|
||||||
netAdapter: adapter,
|
|
||||||
domain: domainInstance,
|
|
||||||
sharedRequestedTransactions: sharedRequestedTransactions,
|
|
||||||
}
|
|
||||||
incomingRoute := router.NewRoute("incoming")
|
|
||||||
outgoingRoute := router.NewRoute("outgoing")
|
|
||||||
defer outgoingRoute.Close()
|
|
||||||
|
|
||||||
txID := externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})
|
|
||||||
txIDs := []*externalapi.DomainTransactionID{txID}
|
|
||||||
|
|
||||||
err = incomingRoute.Enqueue(&appmessage.MsgInvTransaction{TxIDs: txIDs})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error from incomingRoute.Enqueue: %v", err)
|
|
||||||
}
|
|
||||||
incomingRoute.Close()
|
|
||||||
err = transactionrelay.HandleRelayedTransactions(context, incomingRoute, outgoingRoute)
|
|
||||||
if err == nil || !errors.Is(err, router.ErrRouteClosed) {
|
|
||||||
t.Fatalf("Unexpected error: expected: %v, got : %v", router.ErrRouteClosed, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package transactionrelay_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/transactionrelay"
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/logger"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
"github.com/kaspanet/kaspad/util/panics"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestHandleRequestedTransactionsNotFound tests the flow of HandleRequestedTransactions
|
|
||||||
// when the requested transactions don't found in the mempool.
|
|
||||||
func TestHandleRequestedTransactionsNotFound(t *testing.T) {
|
|
||||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
|
||||||
var log = logger.RegisterSubSystem("PROT")
|
|
||||||
var spawn = panics.GoroutineWrapperFunc(log)
|
|
||||||
factory := consensus.NewFactory()
|
|
||||||
tc, teardown, err := factory.NewTestConsensus(consensusConfig, "TestHandleRequestedTransactionsNotFound")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error setting up test Consensus: %+v", err)
|
|
||||||
}
|
|
||||||
defer teardown(false)
|
|
||||||
|
|
||||||
sharedRequestedTransactions := transactionrelay.NewSharedRequestedTransactions()
|
|
||||||
adapter, err := netadapter.NewNetAdapter(config.DefaultConfig())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to create a NetAdapter: %v", err)
|
|
||||||
}
|
|
||||||
domainInstance, err := domain.New(consensusConfig, mempool.DefaultConfig(&consensusConfig.Params), tc.Database())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to set up a domain Instance: %v", err)
|
|
||||||
}
|
|
||||||
context := &mocTransactionsRelayContext{
|
|
||||||
netAdapter: adapter,
|
|
||||||
domain: domainInstance,
|
|
||||||
sharedRequestedTransactions: sharedRequestedTransactions,
|
|
||||||
}
|
|
||||||
incomingRoute := router.NewRoute("incoming")
|
|
||||||
outgoingRoute := router.NewRoute("outgoing")
|
|
||||||
defer outgoingRoute.Close()
|
|
||||||
|
|
||||||
txID1 := externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})
|
|
||||||
txID2 := externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02})
|
|
||||||
txIDs := []*externalapi.DomainTransactionID{txID1, txID2}
|
|
||||||
msg := appmessage.NewMsgRequestTransactions(txIDs)
|
|
||||||
err = incomingRoute.Enqueue(msg)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error from incomingRoute.Enqueue: %v", err)
|
|
||||||
}
|
|
||||||
// The goroutine is representing the peer's actions.
|
|
||||||
spawn("peerResponseToTheTransactionsMessages", func() {
|
|
||||||
for i, id := range txIDs {
|
|
||||||
msg, err := outgoingRoute.Dequeue()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Dequeue: %s", err)
|
|
||||||
}
|
|
||||||
outMsg := msg.(*appmessage.MsgTransactionNotFound)
|
|
||||||
if txIDs[i].String() != outMsg.ID.String() {
|
|
||||||
t.Fatalf("TestHandleRelayedTransactions: expected equal txID: expected %s, but got %s", txIDs[i].String(), id.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Closed the incomingRoute for stop the infinity loop.
|
|
||||||
incomingRoute.Close()
|
|
||||||
})
|
|
||||||
|
|
||||||
err = transactionrelay.HandleRequestedTransactions(context, incomingRoute, outgoingRoute)
|
|
||||||
// Make sure the error is due to the closed route.
|
|
||||||
if err == nil || !errors.Is(err, router.ErrRouteClosed) {
|
|
||||||
t.Fatalf("Unexpected error: expected: %v, got : %v", router.ErrRouteClosed, err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,6 @@ package protocol
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain"
|
"github.com/kaspanet/kaspad/domain"
|
||||||
|
|
||||||
@@ -21,9 +17,7 @@ import (
|
|||||||
|
|
||||||
// Manager manages the p2p protocol
|
// Manager manages the p2p protocol
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
context *flowcontext.FlowContext
|
context *flowcontext.FlowContext
|
||||||
routersWaitGroup sync.WaitGroup
|
|
||||||
isClosed uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager creates a new instance of the p2p protocol manager
|
// NewManager creates a new instance of the p2p protocol manager
|
||||||
@@ -38,18 +32,6 @@ func NewManager(cfg *config.Config, domain domain.Domain, netAdapter *netadapter
|
|||||||
return &manager, nil
|
return &manager, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the protocol manager and waits until all p2p flows
|
|
||||||
// finish.
|
|
||||||
func (m *Manager) Close() {
|
|
||||||
if !atomic.CompareAndSwapUint32(&m.isClosed, 0, 1) {
|
|
||||||
panic(errors.New("The protocol manager was already closed"))
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic.StoreUint32(&m.isClosed, 1)
|
|
||||||
m.context.Close()
|
|
||||||
m.routersWaitGroup.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Peers returns the currently active peers
|
// Peers returns the currently active peers
|
||||||
func (m *Manager) Peers() []*peerpkg.Peer {
|
func (m *Manager) Peers() []*peerpkg.Peer {
|
||||||
return m.context.Peers()
|
return m.context.Peers()
|
||||||
@@ -62,8 +44,8 @@ func (m *Manager) IBDPeer() *peerpkg.Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddTransaction adds transaction to the mempool and propagates it.
|
// AddTransaction adds transaction to the mempool and propagates it.
|
||||||
func (m *Manager) AddTransaction(tx *externalapi.DomainTransaction, allowOrphan bool) error {
|
func (m *Manager) AddTransaction(tx *externalapi.DomainTransaction) error {
|
||||||
return m.context.AddTransaction(tx, allowOrphan)
|
return m.context.AddTransaction(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBlock adds the given block to the DAG and propagates it.
|
// AddBlock adds the given block to the DAG and propagates it.
|
||||||
@@ -71,13 +53,11 @@ func (m *Manager) AddBlock(block *externalapi.DomainBlock) error {
|
|||||||
return m.context.AddBlock(block)
|
return m.context.AddBlock(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) runFlows(flows []*flow, peer *peerpkg.Peer, errChan <-chan error, flowsWaitGroup *sync.WaitGroup) error {
|
func (m *Manager) runFlows(flows []*flow, peer *peerpkg.Peer, errChan <-chan error) error {
|
||||||
flowsWaitGroup.Add(len(flows))
|
|
||||||
for _, flow := range flows {
|
for _, flow := range flows {
|
||||||
executeFunc := flow.executeFunc // extract to new variable so that it's not overwritten
|
executeFunc := flow.executeFunc // extract to new variable so that it's not overwritten
|
||||||
spawn(fmt.Sprintf("flow-%s", flow.name), func() {
|
spawn(fmt.Sprintf("flow-%s", flow.name), func() {
|
||||||
executeFunc(peer)
|
executeFunc(peer)
|
||||||
flowsWaitGroup.Done()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/app/protocol/flows/rejects"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/network/connmanager"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/addressexchange"
|
"github.com/kaspanet/kaspad/app/protocol/flows/addressexchange"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/blockrelay"
|
"github.com/kaspanet/kaspad/app/protocol/flows/blockrelay"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/handshake"
|
"github.com/kaspanet/kaspad/app/protocol/flows/handshake"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/ping"
|
"github.com/kaspanet/kaspad/app/protocol/flows/ping"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/rejects"
|
|
||||||
"github.com/kaspanet/kaspad/app/protocol/flows/transactionrelay"
|
"github.com/kaspanet/kaspad/app/protocol/flows/transactionrelay"
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
"github.com/kaspanet/kaspad/infrastructure/network/addressmanager"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/connmanager"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
||||||
routerpkg "github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
routerpkg "github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -41,13 +41,6 @@ func (m *Manager) routerInitializer(router *routerpkg.Router, netConnection *net
|
|||||||
// After flows were registered - spawn a new thread that will wait for connection to finish initializing
|
// After flows were registered - spawn a new thread that will wait for connection to finish initializing
|
||||||
// and start receiving messages
|
// and start receiving messages
|
||||||
spawn("routerInitializer-runFlows", func() {
|
spawn("routerInitializer-runFlows", func() {
|
||||||
m.routersWaitGroup.Add(1)
|
|
||||||
defer m.routersWaitGroup.Done()
|
|
||||||
|
|
||||||
if atomic.LoadUint32(&m.isClosed) == 1 {
|
|
||||||
panic(errors.Errorf("tried to initialize router when the protocol manager is closed"))
|
|
||||||
}
|
|
||||||
|
|
||||||
isBanned, err := m.context.ConnectionManager().IsBanned(netConnection)
|
isBanned, err := m.context.ConnectionManager().IsBanned(netConnection)
|
||||||
if err != nil && !errors.Is(err, addressmanager.ErrAddressNotFound) {
|
if err != nil && !errors.Is(err, addressmanager.ErrAddressNotFound) {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -86,17 +79,11 @@ func (m *Manager) routerInitializer(router *routerpkg.Router, netConnection *net
|
|||||||
|
|
||||||
removeHandshakeRoutes(router)
|
removeHandshakeRoutes(router)
|
||||||
|
|
||||||
flowsWaitGroup := &sync.WaitGroup{}
|
err = m.runFlows(flows, peer, errChan)
|
||||||
err = m.runFlows(flows, peer, errChan, flowsWaitGroup)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.handleError(err, netConnection, router.OutgoingRoute())
|
m.handleError(err, netConnection, router.OutgoingRoute())
|
||||||
// We call `flowsWaitGroup.Wait()` in two places instead of deferring, because
|
|
||||||
// we already defer `m.routersWaitGroup.Done()`, so we try to avoid error prone
|
|
||||||
// and confusing use of multiple dependent defers.
|
|
||||||
flowsWaitGroup.Wait()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
flowsWaitGroup.Wait()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +93,7 @@ func (m *Manager) handleError(err error, netConnection *netadapter.NetConnection
|
|||||||
log.Warnf("Banning %s (reason: %s)", netConnection, protocolErr.Cause)
|
log.Warnf("Banning %s (reason: %s)", netConnection, protocolErr.Cause)
|
||||||
|
|
||||||
err := m.context.ConnectionManager().Ban(netConnection)
|
err := m.context.ConnectionManager().Ban(netConnection)
|
||||||
if err != nil && !errors.Is(err, connmanager.ErrCannotBanPermanent) {
|
if !errors.Is(err, connmanager.ErrCannotBanPermanent) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,13 +155,10 @@ func (m *Manager) registerBlockRelayFlows(router *routerpkg.Router, isStopping *
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
m.registerFlow("HandleRelayInvs", router, []appmessage.MessageCommand{
|
m.registerFlow("HandleRelayInvs", router, []appmessage.MessageCommand{
|
||||||
appmessage.CmdInvRelayBlock, appmessage.CmdBlock, appmessage.CmdBlockLocator,
|
appmessage.CmdInvRelayBlock, appmessage.CmdBlock, appmessage.CmdBlockLocator, appmessage.CmdIBDBlock,
|
||||||
appmessage.CmdDoneHeaders, appmessage.CmdUnexpectedPruningPoint, appmessage.CmdPruningPointUTXOSetChunk,
|
appmessage.CmdDoneHeaders, appmessage.CmdUnexpectedPruningPoint, appmessage.CmdPruningPointUTXOSetChunk,
|
||||||
appmessage.CmdBlockHeaders, appmessage.CmdIBDBlockLocatorHighestHash, appmessage.CmdBlockWithTrustedData,
|
appmessage.CmdBlockHeaders, appmessage.CmdPruningPointHash, appmessage.CmdIBDBlockLocatorHighestHash,
|
||||||
appmessage.CmdDoneBlocksWithTrustedData, appmessage.CmdIBDBlockLocatorHighestHashNotFound,
|
appmessage.CmdIBDBlockLocatorHighestHashNotFound, appmessage.CmdDonePruningPointUTXOSetChunks},
|
||||||
appmessage.CmdDonePruningPointUTXOSetChunks, appmessage.CmdIBDBlock, appmessage.CmdPruningPoints,
|
|
||||||
appmessage.CmdPruningPointProof,
|
|
||||||
},
|
|
||||||
isStopping, errChan, func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
isStopping, errChan, func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
||||||
return blockrelay.HandleRelayInvs(m.context, incomingRoute,
|
return blockrelay.HandleRelayInvs(m.context, incomingRoute,
|
||||||
outgoingRoute, peer)
|
outgoingRoute, peer)
|
||||||
@@ -201,6 +185,14 @@ func (m *Manager) registerBlockRelayFlows(router *routerpkg.Router, isStopping *
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
m.registerFlow("HandleRequestPruningPointUTXOSetAndBlock", router,
|
||||||
|
[]appmessage.MessageCommand{appmessage.CmdRequestPruningPointUTXOSetAndBlock,
|
||||||
|
appmessage.CmdRequestNextPruningPointUTXOSetChunk}, isStopping, errChan,
|
||||||
|
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
||||||
|
return blockrelay.HandleRequestPruningPointUTXOSetAndBlock(m.context, incomingRoute, outgoingRoute)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
m.registerFlow("HandleIBDBlockRequests", router,
|
m.registerFlow("HandleIBDBlockRequests", router,
|
||||||
[]appmessage.MessageCommand{appmessage.CmdRequestIBDBlocks}, isStopping, errChan,
|
[]appmessage.MessageCommand{appmessage.CmdRequestIBDBlocks}, isStopping, errChan,
|
||||||
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
||||||
@@ -208,18 +200,10 @@ func (m *Manager) registerBlockRelayFlows(router *routerpkg.Router, isStopping *
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
m.registerFlow("HandleRequestPruningPointUTXOSet", router,
|
m.registerFlow("HandlePruningPointHashRequests", router,
|
||||||
[]appmessage.MessageCommand{appmessage.CmdRequestPruningPointUTXOSet,
|
[]appmessage.MessageCommand{appmessage.CmdRequestPruningPointHash}, isStopping, errChan,
|
||||||
appmessage.CmdRequestNextPruningPointUTXOSetChunk}, isStopping, errChan,
|
|
||||||
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
||||||
return blockrelay.HandleRequestPruningPointUTXOSet(m.context, incomingRoute, outgoingRoute)
|
return blockrelay.HandlePruningPointHashRequests(m.context, incomingRoute, outgoingRoute)
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
m.registerFlow("HandlePruningPointAndItsAnticoneRequests", router,
|
|
||||||
[]appmessage.MessageCommand{appmessage.CmdRequestPruningPointAndItsAnticone}, isStopping, errChan,
|
|
||||||
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
|
||||||
return blockrelay.HandlePruningPointAndItsAnticoneRequests(m.context, incomingRoute, outgoingRoute, peer)
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -229,13 +213,6 @@ func (m *Manager) registerBlockRelayFlows(router *routerpkg.Router, isStopping *
|
|||||||
return blockrelay.HandleIBDBlockLocator(m.context, incomingRoute, outgoingRoute, peer)
|
return blockrelay.HandleIBDBlockLocator(m.context, incomingRoute, outgoingRoute, peer)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
m.registerFlow("HandlePruningPointProofRequests", router,
|
|
||||||
[]appmessage.MessageCommand{appmessage.CmdRequestPruningPointProof}, isStopping, errChan,
|
|
||||||
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
|
||||||
return blockrelay.HandlePruningPointProofRequests(m.context, incomingRoute, outgoingRoute, peer)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +238,7 @@ func (m *Manager) registerTransactionRelayFlow(router *routerpkg.Router, isStopp
|
|||||||
outgoingRoute := router.OutgoingRoute()
|
outgoingRoute := router.OutgoingRoute()
|
||||||
|
|
||||||
return []*flow{
|
return []*flow{
|
||||||
m.registerFlowWithCapacity("HandleRelayedTransactions", 10_000, router,
|
m.registerFlow("HandleRelayedTransactions", router,
|
||||||
[]appmessage.MessageCommand{appmessage.CmdInvTransaction, appmessage.CmdTx, appmessage.CmdTransactionNotFound}, isStopping, errChan,
|
[]appmessage.MessageCommand{appmessage.CmdInvTransaction, appmessage.CmdTx, appmessage.CmdTransactionNotFound}, isStopping, errChan,
|
||||||
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
func(incomingRoute *routerpkg.Route, peer *peerpkg.Peer) error {
|
||||||
return transactionrelay.HandleRelayedTransactions(m.context, incomingRoute, outgoingRoute)
|
return transactionrelay.HandleRelayedTransactions(m.context, incomingRoute, outgoingRoute)
|
||||||
@@ -292,29 +269,11 @@ func (m *Manager) registerRejectsFlow(router *routerpkg.Router, isStopping *uint
|
|||||||
func (m *Manager) registerFlow(name string, router *routerpkg.Router, messageTypes []appmessage.MessageCommand, isStopping *uint32,
|
func (m *Manager) registerFlow(name string, router *routerpkg.Router, messageTypes []appmessage.MessageCommand, isStopping *uint32,
|
||||||
errChan chan error, initializeFunc flowInitializeFunc) *flow {
|
errChan chan error, initializeFunc flowInitializeFunc) *flow {
|
||||||
|
|
||||||
route, err := router.AddIncomingRoute(name, messageTypes)
|
route, err := router.AddIncomingRoute(messageTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.registerFlowForRoute(route, name, isStopping, errChan, initializeFunc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) registerFlowWithCapacity(name string, capacity int, router *routerpkg.Router,
|
|
||||||
messageTypes []appmessage.MessageCommand, isStopping *uint32,
|
|
||||||
errChan chan error, initializeFunc flowInitializeFunc) *flow {
|
|
||||||
|
|
||||||
route, err := router.AddIncomingRouteWithCapacity(name, capacity, messageTypes)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.registerFlowForRoute(route, name, isStopping, errChan, initializeFunc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) registerFlowForRoute(route *routerpkg.Route, name string, isStopping *uint32,
|
|
||||||
errChan chan error, initializeFunc flowInitializeFunc) *flow {
|
|
||||||
|
|
||||||
return &flow{
|
return &flow{
|
||||||
name: name,
|
name: name,
|
||||||
executeFunc: func(peer *peerpkg.Peer) {
|
executeFunc: func(peer *peerpkg.Peer) {
|
||||||
@@ -330,7 +289,7 @@ func (m *Manager) registerFlowForRoute(route *routerpkg.Route, name string, isSt
|
|||||||
func (m *Manager) registerOneTimeFlow(name string, router *routerpkg.Router, messageTypes []appmessage.MessageCommand,
|
func (m *Manager) registerOneTimeFlow(name string, router *routerpkg.Router, messageTypes []appmessage.MessageCommand,
|
||||||
isStopping *uint32, stopChan chan error, initializeFunc flowInitializeFunc) *flow {
|
isStopping *uint32, stopChan chan error, initializeFunc flowInitializeFunc) *flow {
|
||||||
|
|
||||||
route, err := router.AddIncomingRoute(name, messageTypes)
|
route, err := router.AddIncomingRoute(messageTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -356,12 +315,12 @@ func (m *Manager) registerOneTimeFlow(name string, router *routerpkg.Router, mes
|
|||||||
|
|
||||||
func registerHandshakeRoutes(router *routerpkg.Router) (
|
func registerHandshakeRoutes(router *routerpkg.Router) (
|
||||||
receiveVersionRoute *routerpkg.Route, sendVersionRoute *routerpkg.Route) {
|
receiveVersionRoute *routerpkg.Route, sendVersionRoute *routerpkg.Route) {
|
||||||
receiveVersionRoute, err := router.AddIncomingRoute("recieveVersion - incoming", []appmessage.MessageCommand{appmessage.CmdVersion})
|
receiveVersionRoute, err := router.AddIncomingRoute([]appmessage.MessageCommand{appmessage.CmdVersion})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendVersionRoute, err = router.AddIncomingRoute("sendVersion - incoming", []appmessage.MessageCommand{appmessage.CmdVerAck})
|
sendVersionRoute, err = router.AddIncomingRoute([]appmessage.MessageCommand{appmessage.CmdVerAck})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,22 +64,17 @@ func (m *Manager) NotifyBlockAddedToDAG(block *externalapi.DomainBlock, blockIns
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.notifyVirtualDaaScoreChanged()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = m.notifyVirtualSelectedParentChainChanged(blockInsertionResult)
|
err = m.notifyVirtualSelectedParentChainChanged(blockInsertionResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcBlock := appmessage.DomainBlockToRPCBlock(block)
|
msgBlock := appmessage.DomainBlockToMsgBlock(block)
|
||||||
err = m.context.PopulateBlockWithVerboseData(rpcBlock, block.Header, block, false)
|
blockVerboseData, err := m.context.BuildBlockVerboseData(block.Header, block, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
blockAddedNotification := appmessage.NewBlockAddedNotificationMessage(rpcBlock)
|
blockAddedNotification := appmessage.NewBlockAddedNotificationMessage(msgBlock, blockVerboseData)
|
||||||
return m.context.NotificationManager.NotifyBlockAdded(blockAddedNotification)
|
return m.context.NotificationManager.NotifyBlockAdded(blockAddedNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,19 +153,6 @@ func (m *Manager) notifyVirtualSelectedParentBlueScoreChanged() error {
|
|||||||
return m.context.NotificationManager.NotifyVirtualSelectedParentBlueScoreChanged(notification)
|
return m.context.NotificationManager.NotifyVirtualSelectedParentBlueScoreChanged(notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) notifyVirtualDaaScoreChanged() error {
|
|
||||||
onEnd := logger.LogAndMeasureExecutionTime(log, "RPCManager.NotifyVirtualDaaScoreChanged")
|
|
||||||
defer onEnd()
|
|
||||||
|
|
||||||
virtualDAAScore, err := m.context.Domain.Consensus().GetVirtualDAAScore()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
notification := appmessage.NewVirtualDaaScoreChangedNotificationMessage(virtualDAAScore)
|
|
||||||
return m.context.NotificationManager.NotifyVirtualDaaScoreChanged(notification)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) notifyVirtualSelectedParentChainChanged(blockInsertionResult *externalapi.BlockInsertionResult) error {
|
func (m *Manager) notifyVirtualSelectedParentChainChanged(blockInsertionResult *externalapi.BlockInsertionResult) error {
|
||||||
onEnd := logger.LogAndMeasureExecutionTime(log, "RPCManager.NotifyVirtualSelectedParentChainChanged")
|
onEnd := logger.LogAndMeasureExecutionTime(log, "RPCManager.NotifyVirtualSelectedParentChainChanged")
|
||||||
defer onEnd()
|
defer onEnd()
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ var handlers = map[appmessage.MessageCommand]handler{
|
|||||||
appmessage.CmdGetInfoRequestMessage: rpchandlers.HandleGetInfo,
|
appmessage.CmdGetInfoRequestMessage: rpchandlers.HandleGetInfo,
|
||||||
appmessage.CmdNotifyPruningPointUTXOSetOverrideRequestMessage: rpchandlers.HandleNotifyPruningPointUTXOSetOverrideRequest,
|
appmessage.CmdNotifyPruningPointUTXOSetOverrideRequestMessage: rpchandlers.HandleNotifyPruningPointUTXOSetOverrideRequest,
|
||||||
appmessage.CmdStopNotifyingPruningPointUTXOSetOverrideRequestMessage: rpchandlers.HandleStopNotifyingPruningPointUTXOSetOverrideRequest,
|
appmessage.CmdStopNotifyingPruningPointUTXOSetOverrideRequestMessage: rpchandlers.HandleStopNotifyingPruningPointUTXOSetOverrideRequest,
|
||||||
appmessage.CmdEstimateNetworkHashesPerSecondRequestMessage: rpchandlers.HandleEstimateNetworkHashesPerSecond,
|
|
||||||
appmessage.CmdNotifyVirtualDaaScoreChangedRequestMessage: rpchandlers.HandleNotifyVirtualDaaScoreChanged,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) routerInitializer(router *router.Router, netConnection *netadapter.NetConnection) {
|
func (m *Manager) routerInitializer(router *router.Router, netConnection *netadapter.NetConnection) {
|
||||||
@@ -53,7 +51,7 @@ func (m *Manager) routerInitializer(router *router.Router, netConnection *netada
|
|||||||
for messageType := range handlers {
|
for messageType := range handlers {
|
||||||
messageTypes = append(messageTypes, messageType)
|
messageTypes = append(messageTypes, messageType)
|
||||||
}
|
}
|
||||||
incomingRoute, err := router.AddIncomingRoute("rpc router", messageTypes)
|
incomingRoute, err := router.AddIncomingRoute(messageTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package rpccontext
|
|||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertVirtualSelectedParentChainChangesToChainChangedNotificationMessage converts
|
// ConvertVirtualSelectedParentChainChangesToChainChangedNotificationMessage converts
|
||||||
@@ -15,9 +16,29 @@ func (ctx *Context) ConvertVirtualSelectedParentChainChangesToChainChangedNotifi
|
|||||||
removedChainBlockHashes[i] = removed.String()
|
removedChainBlockHashes[i] = removed.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
addedChainBlocks := make([]string, len(selectedParentChainChanges.Added))
|
addedChainBlocks := make([]*appmessage.ChainBlock, len(selectedParentChainChanges.Added))
|
||||||
for i, added := range selectedParentChainChanges.Added {
|
for i, added := range selectedParentChainChanges.Added {
|
||||||
addedChainBlocks[i] = added.String()
|
acceptanceData, err := ctx.Domain.Consensus().GetBlockAcceptanceData(added)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
acceptedBlocks := make([]*appmessage.AcceptedBlock, len(acceptanceData))
|
||||||
|
for j, acceptedBlock := range acceptanceData {
|
||||||
|
acceptedTransactionIDs := make([]string, len(acceptedBlock.TransactionAcceptanceData))
|
||||||
|
for k, transaction := range acceptedBlock.TransactionAcceptanceData {
|
||||||
|
transactionID := consensushashing.TransactionID(transaction.Transaction)
|
||||||
|
acceptedTransactionIDs[k] = transactionID.String()
|
||||||
|
}
|
||||||
|
acceptedBlocks[j] = &appmessage.AcceptedBlock{
|
||||||
|
Hash: acceptedBlock.BlockHash.String(),
|
||||||
|
AcceptedTransactionIDs: acceptedTransactionIDs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addedChainBlocks[i] = &appmessage.ChainBlock{
|
||||||
|
Hash: added.String(),
|
||||||
|
AcceptedBlocks: acceptedBlocks,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return appmessage.NewVirtualSelectedParentChainChangedNotificationMessage(removedChainBlockHashes, addedChainBlocks), nil
|
return appmessage.NewVirtualSelectedParentChainChangedNotificationMessage(removedChainBlockHashes, addedChainBlocks), nil
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ type NotificationListener struct {
|
|||||||
propagateFinalityConflictResolvedNotifications bool
|
propagateFinalityConflictResolvedNotifications bool
|
||||||
propagateUTXOsChangedNotifications bool
|
propagateUTXOsChangedNotifications bool
|
||||||
propagateVirtualSelectedParentBlueScoreChangedNotifications bool
|
propagateVirtualSelectedParentBlueScoreChangedNotifications bool
|
||||||
propagateVirtualDaaScoreChangedNotifications bool
|
|
||||||
propagatePruningPointUTXOSetOverrideNotifications bool
|
propagatePruningPointUTXOSetOverrideNotifications bool
|
||||||
|
|
||||||
propagateUTXOsChangedNotificationAddresses map[utxoindex.ScriptPublicKeyString]*UTXOsChangedNotificationAddress
|
propagateUTXOsChangedNotificationAddresses map[utxoindex.ScriptPublicKeyString]*UTXOsChangedNotificationAddress
|
||||||
@@ -182,25 +181,6 @@ func (nm *NotificationManager) NotifyVirtualSelectedParentBlueScoreChanged(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyVirtualDaaScoreChanged notifies the notification manager that the DAG's
|
|
||||||
// virtual DAA score has changed
|
|
||||||
func (nm *NotificationManager) NotifyVirtualDaaScoreChanged(
|
|
||||||
notification *appmessage.VirtualDaaScoreChangedNotificationMessage) error {
|
|
||||||
|
|
||||||
nm.RLock()
|
|
||||||
defer nm.RUnlock()
|
|
||||||
|
|
||||||
for router, listener := range nm.listeners {
|
|
||||||
if listener.propagateVirtualDaaScoreChangedNotifications {
|
|
||||||
err := router.OutgoingRoute().Enqueue(notification)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotifyPruningPointUTXOSetOverride notifies the notification manager that the UTXO index
|
// NotifyPruningPointUTXOSetOverride notifies the notification manager that the UTXO index
|
||||||
// reset due to pruning point change via IBD.
|
// reset due to pruning point change via IBD.
|
||||||
func (nm *NotificationManager) NotifyPruningPointUTXOSetOverride() error {
|
func (nm *NotificationManager) NotifyPruningPointUTXOSetOverride() error {
|
||||||
@@ -328,12 +308,6 @@ func (nl *NotificationListener) PropagateVirtualSelectedParentBlueScoreChangedNo
|
|||||||
nl.propagateVirtualSelectedParentBlueScoreChangedNotifications = true
|
nl.propagateVirtualSelectedParentBlueScoreChangedNotifications = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// PropagateVirtualDaaScoreChangedNotifications instructs the listener to send
|
|
||||||
// virtual DAA score notifications to the remote listener
|
|
||||||
func (nl *NotificationListener) PropagateVirtualDaaScoreChangedNotifications() {
|
|
||||||
nl.propagateVirtualDaaScoreChangedNotifications = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// PropagatePruningPointUTXOSetOverrideNotifications instructs the listener to send pruning point UTXO set override notifications
|
// PropagatePruningPointUTXOSetOverrideNotifications instructs the listener to send pruning point UTXO set override notifications
|
||||||
// to the remote listener.
|
// to the remote listener.
|
||||||
func (nl *NotificationListener) PropagatePruningPointUTXOSetOverrideNotifications() {
|
func (nl *NotificationListener) PropagatePruningPointUTXOSetOverrideNotifications() {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func ConvertUTXOOutpointEntryPairsToUTXOsByAddressesEntries(address string, pair
|
|||||||
UTXOEntry: &appmessage.RPCUTXOEntry{
|
UTXOEntry: &appmessage.RPCUTXOEntry{
|
||||||
Amount: utxoEntry.Amount(),
|
Amount: utxoEntry.Amount(),
|
||||||
ScriptPublicKey: &appmessage.RPCScriptPublicKey{Script: hex.EncodeToString(utxoEntry.ScriptPublicKey().Script), Version: utxoEntry.ScriptPublicKey().Version},
|
ScriptPublicKey: &appmessage.RPCScriptPublicKey{Script: hex.EncodeToString(utxoEntry.ScriptPublicKey().Script), Version: utxoEntry.ScriptPublicKey().Version},
|
||||||
BlockDAAScore: utxoEntry.BlockDAAScore(),
|
BlockBlueScore: utxoEntry.BlockBlueScore(),
|
||||||
IsCoinbase: utxoEntry.IsCoinbase(),
|
IsCoinbase: utxoEntry.IsCoinbase(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,16 +2,23 @@ package rpccontext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
difficultyPackage "github.com/kaspanet/kaspad/util/difficulty"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
|
"github.com/kaspanet/kaspad/util/difficulty"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/estimatedsize"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/subnetworks"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
@@ -21,6 +28,79 @@ import (
|
|||||||
// ErrBuildBlockVerboseDataInvalidBlock indicates that a block that was given to BuildBlockVerboseData is invalid.
|
// ErrBuildBlockVerboseDataInvalidBlock indicates that a block that was given to BuildBlockVerboseData is invalid.
|
||||||
var ErrBuildBlockVerboseDataInvalidBlock = errors.New("ErrBuildBlockVerboseDataInvalidBlock")
|
var ErrBuildBlockVerboseDataInvalidBlock = errors.New("ErrBuildBlockVerboseDataInvalidBlock")
|
||||||
|
|
||||||
|
// BuildBlockVerboseData builds a BlockVerboseData from the given blockHeader.
|
||||||
|
// A block may optionally also be given if it's available in the calling context.
|
||||||
|
func (ctx *Context) BuildBlockVerboseData(blockHeader externalapi.BlockHeader, block *externalapi.DomainBlock,
|
||||||
|
includeTransactionVerboseData bool) (*appmessage.BlockVerboseData, error) {
|
||||||
|
|
||||||
|
onEnd := logger.LogAndMeasureExecutionTime(log, "BuildBlockVerboseData")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
|
hash := consensushashing.HeaderHash(blockHeader)
|
||||||
|
|
||||||
|
blockInfo, err := ctx.Domain.Consensus().GetBlockInfo(hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if blockInfo.BlockStatus == externalapi.StatusInvalid {
|
||||||
|
return nil, errors.Wrap(ErrBuildBlockVerboseDataInvalidBlock, "cannot build verbose data for "+
|
||||||
|
"invalid block")
|
||||||
|
}
|
||||||
|
|
||||||
|
childrenHashes, err := ctx.Domain.Consensus().GetBlockChildren(hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &appmessage.BlockVerboseData{
|
||||||
|
Hash: hash.String(),
|
||||||
|
Version: blockHeader.Version(),
|
||||||
|
VersionHex: fmt.Sprintf("%08x", blockHeader.Version()),
|
||||||
|
HashMerkleRoot: blockHeader.HashMerkleRoot().String(),
|
||||||
|
AcceptedIDMerkleRoot: blockHeader.AcceptedIDMerkleRoot().String(),
|
||||||
|
UTXOCommitment: blockHeader.UTXOCommitment().String(),
|
||||||
|
ParentHashes: hashes.ToStrings(blockHeader.ParentHashes()),
|
||||||
|
ChildrenHashes: hashes.ToStrings(childrenHashes),
|
||||||
|
Nonce: blockHeader.Nonce(),
|
||||||
|
Time: blockHeader.TimeInMilliseconds(),
|
||||||
|
Bits: strconv.FormatInt(int64(blockHeader.Bits()), 16),
|
||||||
|
Difficulty: ctx.GetDifficultyRatio(blockHeader.Bits(), ctx.Config.ActiveNetParams),
|
||||||
|
BlueScore: blockInfo.BlueScore,
|
||||||
|
IsHeaderOnly: blockInfo.BlockStatus == externalapi.StatusHeaderOnly,
|
||||||
|
}
|
||||||
|
|
||||||
|
if blockInfo.BlockStatus != externalapi.StatusHeaderOnly {
|
||||||
|
if block == nil {
|
||||||
|
block, err = ctx.Domain.Consensus().GetBlock(hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
txIDs := make([]string, len(block.Transactions))
|
||||||
|
for i, tx := range block.Transactions {
|
||||||
|
txIDs[i] = consensushashing.TransactionID(tx).String()
|
||||||
|
}
|
||||||
|
result.TxIDs = txIDs
|
||||||
|
|
||||||
|
if includeTransactionVerboseData {
|
||||||
|
transactionVerboseData := make([]*appmessage.TransactionVerboseData, len(block.Transactions))
|
||||||
|
for i, tx := range block.Transactions {
|
||||||
|
txID := consensushashing.TransactionID(tx).String()
|
||||||
|
data, err := ctx.BuildTransactionVerboseData(tx, txID, blockHeader, hash.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
transactionVerboseData[i] = data
|
||||||
|
}
|
||||||
|
result.TransactionVerboseData = transactionVerboseData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetDifficultyRatio returns the proof-of-work difficulty as a multiple of the
|
// GetDifficultyRatio returns the proof-of-work difficulty as a multiple of the
|
||||||
// minimum difficulty using the passed bits field from the header of a block.
|
// minimum difficulty using the passed bits field from the header of a block.
|
||||||
func (ctx *Context) GetDifficultyRatio(bits uint32, params *dagconfig.Params) float64 {
|
func (ctx *Context) GetDifficultyRatio(bits uint32, params *dagconfig.Params) float64 {
|
||||||
@@ -28,7 +108,7 @@ func (ctx *Context) GetDifficultyRatio(bits uint32, params *dagconfig.Params) fl
|
|||||||
// converted back to a number. Note this is not the same as the proof of
|
// converted back to a number. Note this is not the same as the proof of
|
||||||
// work limit directly because the block difficulty is encoded in a block
|
// work limit directly because the block difficulty is encoded in a block
|
||||||
// with the compact form which loses precision.
|
// with the compact form which loses precision.
|
||||||
target := difficultyPackage.CompactToBig(bits)
|
target := difficulty.CompactToBig(bits)
|
||||||
|
|
||||||
difficulty := new(big.Rat).SetFrac(params.PowMax, target)
|
difficulty := new(big.Rat).SetFrac(params.PowMax, target)
|
||||||
diff, _ := difficulty.Float64()
|
diff, _ := difficulty.Float64()
|
||||||
@@ -39,129 +119,106 @@ func (ctx *Context) GetDifficultyRatio(bits uint32, params *dagconfig.Params) fl
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
// PopulateBlockWithVerboseData populates the given `block` with verbose
|
// BuildTransactionVerboseData builds a TransactionVerboseData from
|
||||||
// data from `domainBlockHeader` and optionally from `domainBlock`
|
// the given parameters
|
||||||
func (ctx *Context) PopulateBlockWithVerboseData(block *appmessage.RPCBlock, domainBlockHeader externalapi.BlockHeader,
|
func (ctx *Context) BuildTransactionVerboseData(tx *externalapi.DomainTransaction, txID string,
|
||||||
domainBlock *externalapi.DomainBlock, includeTransactionVerboseData bool) error {
|
blockHeader externalapi.BlockHeader, blockHash string) (
|
||||||
|
*appmessage.TransactionVerboseData, error) {
|
||||||
|
|
||||||
blockHash := consensushashing.HeaderHash(domainBlockHeader)
|
onEnd := logger.LogAndMeasureExecutionTime(log, "BuildTransactionVerboseData")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
blockInfo, err := ctx.Domain.Consensus().GetBlockInfo(blockHash)
|
var payloadHash string
|
||||||
if err != nil {
|
if tx.SubnetworkID != subnetworks.SubnetworkIDNative {
|
||||||
return err
|
payloadHash = tx.PayloadHash.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if blockInfo.BlockStatus == externalapi.StatusInvalid {
|
txReply := &appmessage.TransactionVerboseData{
|
||||||
return errors.Wrap(ErrBuildBlockVerboseDataInvalidBlock, "cannot build verbose data for "+
|
TxID: txID,
|
||||||
"invalid block")
|
Hash: consensushashing.TransactionHash(tx).String(),
|
||||||
|
Size: estimatedsize.TransactionEstimatedSerializedSize(tx),
|
||||||
|
TransactionVerboseInputs: ctx.buildTransactionVerboseInputs(tx),
|
||||||
|
TransactionVerboseOutputs: ctx.buildTransactionVerboseOutputs(tx, nil),
|
||||||
|
Version: tx.Version,
|
||||||
|
LockTime: tx.LockTime,
|
||||||
|
SubnetworkID: tx.SubnetworkID.String(),
|
||||||
|
Gas: tx.Gas,
|
||||||
|
PayloadHash: payloadHash,
|
||||||
|
Payload: hex.EncodeToString(tx.Payload),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, selectedParentHash, childrenHashes, err := ctx.Domain.Consensus().GetBlockRelations(blockHash)
|
if blockHeader != nil {
|
||||||
if err != nil {
|
txReply.Time = uint64(blockHeader.TimeInMilliseconds())
|
||||||
return err
|
txReply.BlockTime = uint64(blockHeader.TimeInMilliseconds())
|
||||||
|
txReply.BlockHash = blockHash
|
||||||
}
|
}
|
||||||
|
|
||||||
block.VerboseData = &appmessage.RPCBlockVerboseData{
|
return txReply, nil
|
||||||
Hash: blockHash.String(),
|
}
|
||||||
Difficulty: ctx.GetDifficultyRatio(domainBlockHeader.Bits(), ctx.Config.ActiveNetParams),
|
|
||||||
ChildrenHashes: hashes.ToStrings(childrenHashes),
|
|
||||||
IsHeaderOnly: blockInfo.BlockStatus == externalapi.StatusHeaderOnly,
|
|
||||||
BlueScore: blockInfo.BlueScore,
|
|
||||||
}
|
|
||||||
// selectedParentHash will be nil in the genesis block
|
|
||||||
if selectedParentHash != nil {
|
|
||||||
block.VerboseData.SelectedParentHash = selectedParentHash.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if blockInfo.BlockStatus == externalapi.StatusHeaderOnly {
|
func (ctx *Context) buildTransactionVerboseInputs(tx *externalapi.DomainTransaction) []*appmessage.TransactionVerboseInput {
|
||||||
return nil
|
inputs := make([]*appmessage.TransactionVerboseInput, len(tx.Inputs))
|
||||||
}
|
for i, transactionInput := range tx.Inputs {
|
||||||
|
// The disassembled string will contain [error] inline
|
||||||
|
// if the script doesn't fully parse, so ignore the
|
||||||
|
// error here.
|
||||||
|
disbuf, _ := txscript.DisasmString(constants.MaxScriptPublicKeyVersion, transactionInput.SignatureScript)
|
||||||
|
|
||||||
// Get the block if we didn't receive it previously
|
input := &appmessage.TransactionVerboseInput{}
|
||||||
if domainBlock == nil {
|
input.TxID = transactionInput.PreviousOutpoint.TransactionID.String()
|
||||||
domainBlock, err = ctx.Domain.Consensus().GetBlockEvenIfHeaderOnly(blockHash)
|
input.OutputIndex = transactionInput.PreviousOutpoint.Index
|
||||||
if err != nil {
|
input.Sequence = transactionInput.Sequence
|
||||||
return err
|
input.ScriptSig = &appmessage.ScriptSig{
|
||||||
|
Asm: disbuf,
|
||||||
|
Hex: hex.EncodeToString(transactionInput.SignatureScript),
|
||||||
}
|
}
|
||||||
|
inputs[i] = input
|
||||||
}
|
}
|
||||||
|
|
||||||
transactionIDs := make([]string, len(domainBlock.Transactions))
|
return inputs
|
||||||
for i, transaction := range domainBlock.Transactions {
|
}
|
||||||
transactionIDs[i] = consensushashing.TransactionID(transaction).String()
|
|
||||||
}
|
|
||||||
block.VerboseData.TransactionIDs = transactionIDs
|
|
||||||
|
|
||||||
if includeTransactionVerboseData {
|
// buildTransactionVerboseOutputs returns a slice of JSON objects for the outputs of the passed
|
||||||
for _, transaction := range block.Transactions {
|
// transaction.
|
||||||
err := ctx.PopulateTransactionWithVerboseData(transaction, domainBlockHeader)
|
func (ctx *Context) buildTransactionVerboseOutputs(tx *externalapi.DomainTransaction, filterAddrMap map[string]struct{}) []*appmessage.TransactionVerboseOutput {
|
||||||
if err != nil {
|
outputs := make([]*appmessage.TransactionVerboseOutput, len(tx.Outputs))
|
||||||
return err
|
for i, transactionOutput := range tx.Outputs {
|
||||||
|
|
||||||
|
// Ignore the error here since an error means the script
|
||||||
|
// couldn't parse and there is no additional information about
|
||||||
|
// it anyways.
|
||||||
|
scriptClass, addr, _ := txscript.ExtractScriptPubKeyAddress(
|
||||||
|
transactionOutput.ScriptPublicKey, ctx.Config.ActiveNetParams)
|
||||||
|
|
||||||
|
// Encode the addresses while checking if the address passes the
|
||||||
|
// filter when needed.
|
||||||
|
passesFilter := len(filterAddrMap) == 0
|
||||||
|
var encodedAddr string
|
||||||
|
if addr != nil {
|
||||||
|
encodedAddr = addr.EncodeAddress()
|
||||||
|
|
||||||
|
// If the filter doesn't already pass, make it pass if
|
||||||
|
// the address exists in the filter.
|
||||||
|
if _, exists := filterAddrMap[encodedAddr]; exists {
|
||||||
|
passesFilter = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
if !passesFilter {
|
||||||
}
|
continue
|
||||||
|
|
||||||
// PopulateTransactionWithVerboseData populates the given `transaction` with
|
|
||||||
// verbose data from `domainTransaction`
|
|
||||||
func (ctx *Context) PopulateTransactionWithVerboseData(
|
|
||||||
transaction *appmessage.RPCTransaction, domainBlockHeader externalapi.BlockHeader) error {
|
|
||||||
|
|
||||||
domainTransaction, err := appmessage.RPCTransactionToDomainTransaction(transaction)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Domain.Consensus().PopulateMass(domainTransaction)
|
|
||||||
transaction.VerboseData = &appmessage.RPCTransactionVerboseData{
|
|
||||||
TransactionID: consensushashing.TransactionID(domainTransaction).String(),
|
|
||||||
Hash: consensushashing.TransactionHash(domainTransaction).String(),
|
|
||||||
Mass: domainTransaction.Mass,
|
|
||||||
}
|
|
||||||
if domainBlockHeader != nil {
|
|
||||||
transaction.VerboseData.BlockHash = consensushashing.HeaderHash(domainBlockHeader).String()
|
|
||||||
transaction.VerboseData.BlockTime = uint64(domainBlockHeader.TimeInMilliseconds())
|
|
||||||
}
|
|
||||||
for _, input := range transaction.Inputs {
|
|
||||||
ctx.populateTransactionInputWithVerboseData(input)
|
|
||||||
}
|
|
||||||
for _, output := range transaction.Outputs {
|
|
||||||
err := ctx.populateTransactionOutputWithVerboseData(output)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output := &appmessage.TransactionVerboseOutput{}
|
||||||
|
output.Index = uint32(i)
|
||||||
|
output.Value = transactionOutput.Value
|
||||||
|
output.ScriptPubKey = &appmessage.ScriptPubKeyResult{
|
||||||
|
Version: transactionOutput.ScriptPublicKey.Version,
|
||||||
|
Address: encodedAddr,
|
||||||
|
Hex: hex.EncodeToString(transactionOutput.ScriptPublicKey.Script),
|
||||||
|
Type: scriptClass.String(),
|
||||||
|
}
|
||||||
|
outputs[i] = output
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
return outputs
|
||||||
|
|
||||||
func (ctx *Context) populateTransactionInputWithVerboseData(transactionInput *appmessage.RPCTransactionInput) {
|
|
||||||
transactionInput.VerboseData = &appmessage.RPCTransactionInputVerboseData{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctx *Context) populateTransactionOutputWithVerboseData(transactionOutput *appmessage.RPCTransactionOutput) error {
|
|
||||||
scriptPublicKey, err := hex.DecodeString(transactionOutput.ScriptPublicKey.Script)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
domainScriptPublicKey := &externalapi.ScriptPublicKey{
|
|
||||||
Script: scriptPublicKey,
|
|
||||||
Version: transactionOutput.ScriptPublicKey.Version,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore the error here since an error means the script
|
|
||||||
// couldn't be parsed and there's no additional information about
|
|
||||||
// it anyways
|
|
||||||
scriptPublicKeyType, scriptPublicKeyAddress, _ := txscript.ExtractScriptPubKeyAddress(
|
|
||||||
domainScriptPublicKey, ctx.Config.ActiveNetParams)
|
|
||||||
|
|
||||||
var encodedScriptPublicKeyAddress string
|
|
||||||
if scriptPublicKeyAddress != nil {
|
|
||||||
encodedScriptPublicKeyAddress = scriptPublicKeyAddress.EncodeAddress()
|
|
||||||
}
|
|
||||||
transactionOutput.VerboseData = &appmessage.RPCTransactionOutputVerboseData{
|
|
||||||
ScriptPublicKeyType: scriptPublicKeyType.String(),
|
|
||||||
ScriptPublicKeyAddress: encodedScriptPublicKeyAddress,
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,8 @@ func HandleBan(context *rpccontext.Context, _ *router.Router, request appmessage
|
|||||||
banRequest := request.(*appmessage.BanRequestMessage)
|
banRequest := request.(*appmessage.BanRequestMessage)
|
||||||
ip := net.ParseIP(banRequest.IP)
|
ip := net.ParseIP(banRequest.IP)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
hint := ""
|
|
||||||
if banRequest.IP[0] == '[' {
|
|
||||||
hint = " (try to remove “[” and “]” symbols)"
|
|
||||||
}
|
|
||||||
errorMessage := &appmessage.BanResponseMessage{}
|
errorMessage := &appmessage.BanResponseMessage{}
|
||||||
errorMessage.Error = appmessage.RPCErrorf("Could not parse IP%s: %s", hint, banRequest.IP)
|
errorMessage.Error = appmessage.RPCErrorf("Could not parse IP %s", banRequest.IP)
|
||||||
return errorMessage, nil
|
return errorMessage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package rpchandlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HandleEstimateNetworkHashesPerSecond handles the respectively named RPC command
|
|
||||||
func HandleEstimateNetworkHashesPerSecond(
|
|
||||||
context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) {
|
|
||||||
|
|
||||||
estimateNetworkHashesPerSecondRequest := request.(*appmessage.EstimateNetworkHashesPerSecondRequestMessage)
|
|
||||||
|
|
||||||
windowSize := int(estimateNetworkHashesPerSecondRequest.WindowSize)
|
|
||||||
startHash := model.VirtualBlockHash
|
|
||||||
if estimateNetworkHashesPerSecondRequest.StartHash != "" {
|
|
||||||
var err error
|
|
||||||
startHash, err = externalapi.NewDomainHashFromString(estimateNetworkHashesPerSecondRequest.StartHash)
|
|
||||||
if err != nil {
|
|
||||||
response := &appmessage.EstimateNetworkHashesPerSecondResponseMessage{}
|
|
||||||
response.Error = appmessage.RPCErrorf("StartHash '%s' is not a valid block hash",
|
|
||||||
estimateNetworkHashesPerSecondRequest.StartHash)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
networkHashesPerSecond, err := context.Domain.Consensus().EstimateNetworkHashesPerSecond(startHash, windowSize)
|
|
||||||
if err != nil {
|
|
||||||
response := &appmessage.EstimateNetworkHashesPerSecondResponseMessage{}
|
|
||||||
response.Error = appmessage.RPCErrorf("could not resolve network hashes per "+
|
|
||||||
"second for startHash %s and window size %d: %s", startHash, windowSize, err)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return appmessage.NewEstimateNetworkHashesPerSecondResponseMessage(networkHashesPerSecond), nil
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ func HandleGetBlock(context *rpccontext.Context, _ *router.Router, request appme
|
|||||||
return errorMessage, nil
|
return errorMessage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
block, err := context.Domain.Consensus().GetBlockEvenIfHeaderOnly(hash)
|
header, err := context.Domain.Consensus().GetBlockHeader(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorMessage := &appmessage.GetBlockResponseMessage{}
|
errorMessage := &appmessage.GetBlockResponseMessage{}
|
||||||
errorMessage.Error = appmessage.RPCErrorf("Block %s not found", hash)
|
errorMessage.Error = appmessage.RPCErrorf("Block %s not found", hash)
|
||||||
@@ -29,13 +29,7 @@ func HandleGetBlock(context *rpccontext.Context, _ *router.Router, request appme
|
|||||||
|
|
||||||
response := appmessage.NewGetBlockResponseMessage()
|
response := appmessage.NewGetBlockResponseMessage()
|
||||||
|
|
||||||
if getBlockRequest.IncludeTransactions {
|
blockVerboseData, err := context.BuildBlockVerboseData(header, nil, getBlockRequest.IncludeTransactionVerboseData)
|
||||||
response.Block = appmessage.DomainBlockToRPCBlock(block)
|
|
||||||
} else {
|
|
||||||
response.Block = appmessage.DomainBlockToRPCBlock(&externalapi.DomainBlock{Header: block.Header})
|
|
||||||
}
|
|
||||||
|
|
||||||
err = context.PopulateBlockWithVerboseData(response.Block, block.Header, block, getBlockRequest.IncludeTransactions)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, rpccontext.ErrBuildBlockVerboseDataInvalidBlock) {
|
if errors.Is(err, rpccontext.ErrBuildBlockVerboseDataInvalidBlock) {
|
||||||
errorMessage := &appmessage.GetBlockResponseMessage{}
|
errorMessage := &appmessage.GetBlockResponseMessage{}
|
||||||
@@ -45,5 +39,7 @@ func HandleGetBlock(context *rpccontext.Context, _ *router.Router, request appme
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.BlockVerboseData = blockVerboseData
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ func HandleGetBlockDAGInfo(context *rpccontext.Context, _ *router.Router, _ appm
|
|||||||
response.VirtualParentHashes = hashes.ToStrings(virtualInfo.ParentHashes)
|
response.VirtualParentHashes = hashes.ToStrings(virtualInfo.ParentHashes)
|
||||||
response.Difficulty = context.GetDifficultyRatio(virtualInfo.Bits, context.Config.ActiveNetParams)
|
response.Difficulty = context.GetDifficultyRatio(virtualInfo.Bits, context.Config.ActiveNetParams)
|
||||||
response.PastMedianTime = virtualInfo.PastMedianTime
|
response.PastMedianTime = virtualInfo.PastMedianTime
|
||||||
response.VirtualDAAScore = virtualInfo.DAAScore
|
|
||||||
|
|
||||||
pruningPoint, err := context.Domain.Consensus().PruningPoint()
|
pruningPoint, err := context.Domain.Consensus().PruningPoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ func HandleGetBlockTemplate(context *rpccontext.Context, _ *router.Router, reque
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rpcBlock := appmessage.DomainBlockToRPCBlock(templateBlock)
|
msgBlock := appmessage.DomainBlockToMsgBlock(templateBlock)
|
||||||
|
|
||||||
isSynced, err := context.ProtocolManager.ShouldMine()
|
isSynced, err := context.ProtocolManager.ShouldMine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return appmessage.NewGetBlockTemplateResponseMessage(rpcBlock, isSynced), nil
|
return appmessage.NewGetBlockTemplateResponseMessage(msgBlock, isSynced), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,21 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// maxBlocksInGetBlocksResponse is the max amount of blocks that are
|
||||||
|
// allowed in a GetBlocksResult.
|
||||||
|
maxBlocksInGetBlocksResponse = 1000
|
||||||
|
)
|
||||||
|
|
||||||
// HandleGetBlocks handles the respectively named RPC command
|
// HandleGetBlocks handles the respectively named RPC command
|
||||||
func HandleGetBlocks(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) {
|
func HandleGetBlocks(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) {
|
||||||
getBlocksRequest := request.(*appmessage.GetBlocksRequestMessage)
|
getBlocksRequest := request.(*appmessage.GetBlocksRequestMessage)
|
||||||
|
|
||||||
// Validate that user didn't set IncludeTransactions without setting IncludeBlocks
|
// Validate that user didn't set IncludeTransactionVerboseData without setting IncludeBlockVerboseData
|
||||||
if !getBlocksRequest.IncludeBlocks && getBlocksRequest.IncludeTransactions {
|
if !getBlocksRequest.IncludeBlockVerboseData && getBlocksRequest.IncludeTransactionVerboseData {
|
||||||
return &appmessage.GetBlocksResponseMessage{
|
return &appmessage.GetBlocksResponseMessage{
|
||||||
Error: appmessage.RPCErrorf(
|
Error: appmessage.RPCErrorf(
|
||||||
"If includeTransactions is set, then includeBlockVerboseData must be set as well"),
|
"If includeTransactionVerboseData is set, then includeBlockVerboseData must be set as well"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,11 +55,8 @@ func HandleGetBlocks(context *rpccontext.Context, _ *router.Router, request appm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
blockHashes, err := context.Domain.Consensus().GetHashesBetween(
|
||||||
// We use +1 because lowHash is also returned
|
lowHash, virtualSelectedParent, maxBlocksInGetBlocksResponse)
|
||||||
// maxBlocks MUST be >= MergeSetSizeLimit + 1
|
|
||||||
maxBlocks := context.Config.NetParams().MergeSetSizeLimit + 1
|
|
||||||
blockHashes, highHash, err := context.Domain.Consensus().GetHashesBetween(lowHash, virtualSelectedParent, maxBlocks)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -61,10 +64,9 @@ func HandleGetBlocks(context *rpccontext.Context, _ *router.Router, request appm
|
|||||||
// prepend low hash to make it inclusive
|
// prepend low hash to make it inclusive
|
||||||
blockHashes = append([]*externalapi.DomainHash{lowHash}, blockHashes...)
|
blockHashes = append([]*externalapi.DomainHash{lowHash}, blockHashes...)
|
||||||
|
|
||||||
// If the high hash is equal to virtualSelectedParent it means GetHashesBetween didn't skip any hashes, and
|
// If there are no maxBlocksInGetBlocksResponse between lowHash and virtualSelectedParent -
|
||||||
// there's space to add the virtualSelectedParent's anticone, otherwise you can't add the anticone because
|
// add virtualSelectedParent's anticone
|
||||||
// there's no guarantee that all of the anticone root ancestors will be present.
|
if len(blockHashes) < maxBlocksInGetBlocksResponse {
|
||||||
if highHash.Equal(virtualSelectedParent) {
|
|
||||||
virtualSelectedParentAnticone, err := context.Domain.Consensus().Anticone(virtualSelectedParent)
|
virtualSelectedParentAnticone, err := context.Domain.Consensus().Anticone(virtualSelectedParent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -72,29 +74,33 @@ func HandleGetBlocks(context *rpccontext.Context, _ *router.Router, request appm
|
|||||||
blockHashes = append(blockHashes, virtualSelectedParentAnticone...)
|
blockHashes = append(blockHashes, virtualSelectedParentAnticone...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the response
|
// Both GetHashesBetween and Anticone might return more then the allowed number of blocks, so
|
||||||
response := appmessage.NewGetBlocksResponseMessage()
|
// trim any extra blocks.
|
||||||
response.BlockHashes = hashes.ToStrings(blockHashes)
|
if len(blockHashes) > maxBlocksInGetBlocksResponse {
|
||||||
if getBlocksRequest.IncludeBlocks {
|
blockHashes = blockHashes[:maxBlocksInGetBlocksResponse]
|
||||||
rpcBlocks := make([]*appmessage.RPCBlock, len(blockHashes))
|
|
||||||
for i, blockHash := range blockHashes {
|
|
||||||
block, err := context.Domain.Consensus().GetBlockEvenIfHeaderOnly(blockHash)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if getBlocksRequest.IncludeTransactions {
|
|
||||||
rpcBlocks[i] = appmessage.DomainBlockToRPCBlock(block)
|
|
||||||
} else {
|
|
||||||
rpcBlocks[i] = appmessage.DomainBlockToRPCBlock(&externalapi.DomainBlock{Header: block.Header})
|
|
||||||
}
|
|
||||||
err = context.PopulateBlockWithVerboseData(rpcBlocks[i], block.Header, nil, getBlocksRequest.IncludeTransactions)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
response.Blocks = rpcBlocks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare the response
|
||||||
|
response := &appmessage.GetBlocksResponseMessage{
|
||||||
|
BlockHashes: hashes.ToStrings(blockHashes),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve all block data in case BlockVerboseData was requested
|
||||||
|
if getBlocksRequest.IncludeBlockVerboseData {
|
||||||
|
response.BlockVerboseData = make([]*appmessage.BlockVerboseData, len(blockHashes))
|
||||||
|
for i, blockHash := range blockHashes {
|
||||||
|
blockHeader, err := context.Domain.Consensus().GetBlockHeader(blockHash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
blockVerboseData, err := context.BuildBlockVerboseData(blockHeader, nil,
|
||||||
|
getBlocksRequest.IncludeTransactionVerboseData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response.BlockVerboseData[i] = blockVerboseData
|
||||||
|
}
|
||||||
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpchandlers"
|
"github.com/kaspanet/kaspad/app/rpc/rpchandlers"
|
||||||
@@ -15,6 +13,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/model/testapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/testapi"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
|
||||||
|
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager"
|
"github.com/kaspanet/kaspad/domain/miningmanager"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
||||||
)
|
)
|
||||||
@@ -23,38 +22,20 @@ type fakeDomain struct {
|
|||||||
testapi.TestConsensus
|
testapi.TestConsensus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d fakeDomain) DeleteStagingConsensus() error {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d fakeDomain) StagingConsensus() externalapi.Consensus {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d fakeDomain) InitStagingConsensus() error {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d fakeDomain) CommitStagingConsensus() error {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d fakeDomain) Consensus() externalapi.Consensus { return d }
|
func (d fakeDomain) Consensus() externalapi.Consensus { return d }
|
||||||
func (d fakeDomain) MiningManager() miningmanager.MiningManager { return nil }
|
func (d fakeDomain) MiningManager() miningmanager.MiningManager { return nil }
|
||||||
|
|
||||||
func TestHandleGetBlocks(t *testing.T) {
|
func TestHandleGetBlocks(t *testing.T) {
|
||||||
testutils.ForAllNets(t, true, func(t *testing.T, consensusConfig *consensus.Config) {
|
testutils.ForAllNets(t, true, func(t *testing.T, params *dagconfig.Params) {
|
||||||
stagingArea := model.NewStagingArea()
|
|
||||||
|
|
||||||
factory := consensus.NewFactory()
|
factory := consensus.NewFactory()
|
||||||
tc, teardown, err := factory.NewTestConsensus(consensusConfig, "TestHandleGetBlocks")
|
tc, teardown, err := factory.NewTestConsensus(params, false, "TestHandleGetBlocks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error setting up consensus: %+v", err)
|
t.Fatalf("Error setting up consensus: %+v", err)
|
||||||
}
|
}
|
||||||
defer teardown(false)
|
defer teardown(false)
|
||||||
|
|
||||||
fakeContext := rpccontext.Context{
|
fakeContext := rpccontext.Context{
|
||||||
Config: &config.Config{Flags: &config.Flags{NetworkFlags: config.NetworkFlags{ActiveNetParams: &consensusConfig.Params}}},
|
Config: &config.Config{Flags: &config.Flags{NetworkFlags: config.NetworkFlags{ActiveNetParams: params}}},
|
||||||
Domain: fakeDomain{tc},
|
Domain: fakeDomain{tc},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +55,7 @@ func TestHandleGetBlocks(t *testing.T) {
|
|||||||
antipast := make([]*externalapi.DomainHash, 0, len(slice))
|
antipast := make([]*externalapi.DomainHash, 0, len(slice))
|
||||||
|
|
||||||
for _, blockHash := range slice {
|
for _, blockHash := range slice {
|
||||||
isInPastOfPovBlock, err := tc.DAGTopologyManager().IsAncestorOf(stagingArea, blockHash, povBlock)
|
isInPastOfPovBlock, err := tc.DAGTopologyManager().IsAncestorOf(blockHash, povBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed doing reachability check: '%v'", err)
|
t.Fatalf("Failed doing reachability check: '%v'", err)
|
||||||
}
|
}
|
||||||
@@ -96,7 +77,7 @@ func TestHandleGetBlocks(t *testing.T) {
|
|||||||
// \ | /
|
// \ | /
|
||||||
// etc.
|
// etc.
|
||||||
expectedOrder := make([]*externalapi.DomainHash, 0, 40)
|
expectedOrder := make([]*externalapi.DomainHash, 0, 40)
|
||||||
mergingBlock := consensusConfig.GenesisHash
|
mergingBlock := params.GenesisHash
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
splitBlocks := make([]*externalapi.DomainHash, 0, 3)
|
splitBlocks := make([]*externalapi.DomainHash, 0, 3)
|
||||||
for j := 0; j < 3; j++ {
|
for j := 0; j < 3; j++ {
|
||||||
@@ -106,7 +87,7 @@ func TestHandleGetBlocks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
splitBlocks = append(splitBlocks, blockHash)
|
splitBlocks = append(splitBlocks, blockHash)
|
||||||
}
|
}
|
||||||
sort.Sort(sort.Reverse(testutils.NewTestGhostDAGSorter(stagingArea, splitBlocks, tc, t)))
|
sort.Sort(sort.Reverse(testutils.NewTestGhostDAGSorter(splitBlocks, tc, t)))
|
||||||
restOfSplitBlocks, selectedParent := splitBlocks[:len(splitBlocks)-1], splitBlocks[len(splitBlocks)-1]
|
restOfSplitBlocks, selectedParent := splitBlocks[:len(splitBlocks)-1], splitBlocks[len(splitBlocks)-1]
|
||||||
expectedOrder = append(expectedOrder, selectedParent)
|
expectedOrder = append(expectedOrder, selectedParent)
|
||||||
expectedOrder = append(expectedOrder, restOfSplitBlocks...)
|
expectedOrder = append(expectedOrder, restOfSplitBlocks...)
|
||||||
@@ -149,13 +130,13 @@ func TestHandleGetBlocks(t *testing.T) {
|
|||||||
virtualSelectedParent, actualBlocks.BlockHashes)
|
virtualSelectedParent, actualBlocks.BlockHashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedOrder = append([]*externalapi.DomainHash{consensusConfig.GenesisHash}, expectedOrder...)
|
expectedOrder = append([]*externalapi.DomainHash{params.GenesisHash}, expectedOrder...)
|
||||||
actualOrder := getBlocks(nil)
|
actualOrder := getBlocks(nil)
|
||||||
if !reflect.DeepEqual(actualOrder.BlockHashes, hashes.ToStrings(expectedOrder)) {
|
if !reflect.DeepEqual(actualOrder.BlockHashes, hashes.ToStrings(expectedOrder)) {
|
||||||
t.Fatalf("TestHandleGetBlocks \nexpected: %v \nactual:\n%v", expectedOrder, actualOrder.BlockHashes)
|
t.Fatalf("TestHandleGetBlocks \nexpected: %v \nactual:\n%v", expectedOrder, actualOrder.BlockHashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
requestAllExplictly := getBlocks(consensusConfig.GenesisHash)
|
requestAllExplictly := getBlocks(params.GenesisHash)
|
||||||
if !reflect.DeepEqual(requestAllExplictly.BlockHashes, hashes.ToStrings(expectedOrder)) {
|
if !reflect.DeepEqual(requestAllExplictly.BlockHashes, hashes.ToStrings(expectedOrder)) {
|
||||||
t.Fatalf("TestHandleGetBlocks \nexpected: \n%v\n. actual:\n%v", expectedOrder, requestAllExplictly.BlockHashes)
|
t.Fatalf("TestHandleGetBlocks \nexpected: \n%v\n. actual:\n%v", expectedOrder, requestAllExplictly.BlockHashes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,10 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
"github.com/kaspanet/kaspad/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleGetInfo handles the respectively named RPC command
|
// HandleGetInfo handles the respectively named RPC command
|
||||||
func HandleGetInfo(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
func HandleGetInfo(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
||||||
response := appmessage.NewGetInfoResponseMessage(
|
response := appmessage.NewGetInfoResponseMessage(context.NetAdapter.ID().String())
|
||||||
context.NetAdapter.ID().String(),
|
|
||||||
uint64(context.Domain.MiningManager().TransactionCount()),
|
|
||||||
version.Version(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,25 @@ package rpchandlers
|
|||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleGetMempoolEntries handles the respectively named RPC command
|
// HandleGetMempoolEntries handles the respectively named RPC command
|
||||||
func HandleGetMempoolEntries(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
func HandleGetMempoolEntries(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
||||||
|
|
||||||
transactions := context.Domain.MiningManager().AllTransactions()
|
transactions := context.Domain.MiningManager().AllTransactions()
|
||||||
entries := make([]*appmessage.MempoolEntry, 0, len(transactions))
|
entries := make([]*appmessage.MempoolEntry, 0, len(transactions))
|
||||||
for _, transaction := range transactions {
|
for _, tx := range transactions {
|
||||||
rpcTransaction := appmessage.DomainTransactionToRPCTransaction(transaction)
|
transactionVerboseData, err := context.BuildTransactionVerboseData(
|
||||||
err := context.PopulateTransactionWithVerboseData(rpcTransaction, nil)
|
tx, consensushashing.TransactionID(tx).String(), nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = append(entries, &appmessage.MempoolEntry{
|
entries = append(entries, &appmessage.MempoolEntry{
|
||||||
Fee: transaction.Fee,
|
Fee: tx.Fee,
|
||||||
Transaction: rpcTransaction,
|
TransactionVerboseData: transactionVerboseData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ func HandleGetMempoolEntry(context *rpccontext.Context, _ *router.Router, reques
|
|||||||
errorMessage.Error = appmessage.RPCErrorf("Transaction %s was not found", transactionID)
|
errorMessage.Error = appmessage.RPCErrorf("Transaction %s was not found", transactionID)
|
||||||
return errorMessage, nil
|
return errorMessage, nil
|
||||||
}
|
}
|
||||||
rpcTransaction := appmessage.DomainTransactionToRPCTransaction(transaction)
|
|
||||||
err = context.PopulateTransactionWithVerboseData(rpcTransaction, nil)
|
transactionVerboseData, err := context.BuildTransactionVerboseData(
|
||||||
|
transaction, getMempoolEntryRequest.TxID, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return appmessage.NewGetMempoolEntryResponseMessage(transaction.Fee, rpcTransaction), nil
|
return appmessage.NewGetMempoolEntryResponseMessage(transaction.Fee, transactionVerboseData), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,9 @@ import (
|
|||||||
|
|
||||||
// HandleGetVirtualSelectedParentBlueScore handles the respectively named RPC command
|
// HandleGetVirtualSelectedParentBlueScore handles the respectively named RPC command
|
||||||
func HandleGetVirtualSelectedParentBlueScore(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
func HandleGetVirtualSelectedParentBlueScore(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
||||||
c := context.Domain.Consensus()
|
virtualInfo, err := context.Domain.Consensus().GetVirtualInfo()
|
||||||
selectedParent, err := c.GetVirtualSelectedParent()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
blockInfo, err := c.GetBlockInfo(selectedParent)
|
return appmessage.NewGetVirtualSelectedParentBlueScoreResponseMessage(virtualInfo.BlueScore), nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return appmessage.NewGetVirtualSelectedParentBlueScoreResponseMessage(blockInfo.BlueScore), nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ func HandleGetVirtualSelectedParentChainFromBlock(context *rpccontext.Context, _
|
|||||||
}
|
}
|
||||||
|
|
||||||
response := appmessage.NewGetVirtualSelectedParentChainFromBlockResponseMessage(
|
response := appmessage.NewGetVirtualSelectedParentChainFromBlockResponseMessage(
|
||||||
chainChangedNotification.RemovedChainBlockHashes, chainChangedNotification.AddedChainBlockHashes)
|
chainChangedNotification.RemovedChainBlockHashes, chainChangedNotification.AddedChainBlocks)
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package rpchandlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HandleNotifyVirtualDaaScoreChanged handles the respectively named RPC command
|
|
||||||
func HandleNotifyVirtualDaaScoreChanged(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
|
||||||
listener, err := context.NotificationManager.Listener(router)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
listener.PropagateVirtualDaaScoreChangedNotifications()
|
|
||||||
|
|
||||||
response := appmessage.NewNotifyVirtualDaaScoreChangedResponseMessage()
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,9 @@ import (
|
|||||||
func HandleSubmitBlock(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) {
|
func HandleSubmitBlock(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) {
|
||||||
submitBlockRequest := request.(*appmessage.SubmitBlockRequestMessage)
|
submitBlockRequest := request.(*appmessage.SubmitBlockRequestMessage)
|
||||||
|
|
||||||
|
msgBlock := submitBlockRequest.Block
|
||||||
|
domainBlock := appmessage.MsgBlockToDomainBlock(msgBlock)
|
||||||
|
|
||||||
if context.ProtocolManager.IsIBDRunning() {
|
if context.ProtocolManager.IsIBDRunning() {
|
||||||
return &appmessage.SubmitBlockResponseMessage{
|
return &appmessage.SubmitBlockResponseMessage{
|
||||||
Error: appmessage.RPCErrorf("Block not submitted - IBD is running"),
|
Error: appmessage.RPCErrorf("Block not submitted - IBD is running"),
|
||||||
@@ -21,15 +24,7 @@ func HandleSubmitBlock(context *rpccontext.Context, _ *router.Router, request ap
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
domainBlock, err := appmessage.RPCBlockToDomainBlock(submitBlockRequest.Block)
|
err := context.ProtocolManager.AddBlock(domainBlock)
|
||||||
if err != nil {
|
|
||||||
return &appmessage.SubmitBlockResponseMessage{
|
|
||||||
Error: appmessage.RPCErrorf("Could not parse block: %s", err),
|
|
||||||
RejectReason: appmessage.RejectReasonBlockInvalid,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = context.ProtocolManager.AddBlock(domainBlock)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
isProtocolOrRuleError := errors.As(err, &ruleerrors.RuleError{}) || errors.As(err, &protocolerrors.ProtocolError{})
|
isProtocolOrRuleError := errors.As(err, &ruleerrors.RuleError{}) || errors.As(err, &protocolerrors.ProtocolError{})
|
||||||
if !isProtocolOrRuleError {
|
if !isProtocolOrRuleError {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func HandleSubmitTransaction(context *rpccontext.Context, _ *router.Router, requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
transactionID := consensushashing.TransactionID(domainTransaction)
|
transactionID := consensushashing.TransactionID(domainTransaction)
|
||||||
err = context.ProtocolManager.AddTransaction(domainTransaction, submitTransactionRequest.AllowOrphan)
|
err = context.ProtocolManager.AddTransaction(domainTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.As(err, &mempool.RuleError{}) {
|
if !errors.As(err, &mempool.RuleError{}) {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -12,15 +12,11 @@ func HandleUnban(context *rpccontext.Context, _ *router.Router, request appmessa
|
|||||||
unbanRequest := request.(*appmessage.UnbanRequestMessage)
|
unbanRequest := request.(*appmessage.UnbanRequestMessage)
|
||||||
ip := net.ParseIP(unbanRequest.IP)
|
ip := net.ParseIP(unbanRequest.IP)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
hint := ""
|
|
||||||
if unbanRequest.IP[0] == '[' {
|
|
||||||
hint = " (try to remove “[” and “]” symbols)"
|
|
||||||
}
|
|
||||||
errorMessage := &appmessage.UnbanResponseMessage{}
|
errorMessage := &appmessage.UnbanResponseMessage{}
|
||||||
errorMessage.Error = appmessage.RPCErrorf("Could not parse IP%s: %s", hint, unbanRequest.IP)
|
errorMessage.Error = appmessage.RPCErrorf("Could not parse IP %s", unbanRequest.IP)
|
||||||
return errorMessage, nil
|
return errorMessage, nil
|
||||||
}
|
}
|
||||||
err := context.AddressManager.Unban(appmessage.NewNetAddressIPPort(ip, 0))
|
err := context.AddressManager.Unban(appmessage.NewNetAddressIPPort(ip, 0, 0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorMessage := &appmessage.UnbanResponseMessage{}
|
errorMessage := &appmessage.UnbanResponseMessage{}
|
||||||
errorMessage.Error = appmessage.RPCErrorf("Could not unban IP: %s", err)
|
errorMessage.Error = appmessage.RPCErrorf("Could not unban IP: %s", err)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ go build $FLAGS -o kaspad .
|
|||||||
|
|
||||||
if [ -n "${NO_PARALLEL}" ]
|
if [ -n "${NO_PARALLEL}" ]
|
||||||
then
|
then
|
||||||
go test -timeout 20m -parallel=1 $FLAGS ./...
|
go test -parallel=1 $FLAGS ./...
|
||||||
else
|
else
|
||||||
go test -timeout 20m $FLAGS ./...
|
go test $FLAGS ./...
|
||||||
fi
|
fi
|
||||||
@@ -1,79 +1,3 @@
|
|||||||
Kaspad v0.11.2 - 2021-11-11
|
|
||||||
===========================
|
|
||||||
Bug fixes:
|
|
||||||
* Enlarge p2p max message size to 1gb
|
|
||||||
* Fix UTXO chunks logic
|
|
||||||
* Increase tests timeout to 20 minutes
|
|
||||||
|
|
||||||
Kaspad v0.11.1 - 2021-11-09
|
|
||||||
===========================
|
|
||||||
Non-breaking changes:
|
|
||||||
* Cache the miner state
|
|
||||||
|
|
||||||
Kaspad v0.10.2 - 2021-05-18
|
|
||||||
===========================
|
|
||||||
Non-breaking changes:
|
|
||||||
* Fix getBlock and getBlocks RPC commands to return blocks and transactions properly (#1716)
|
|
||||||
* serializeAddress should always serialize as IPv6, since it assumes the IP size is 16 bytes (#1720)
|
|
||||||
* Add VirtualDaaScore to GetBlockDagInfo (#1719)
|
|
||||||
* Fix calcTxSequenceLockFromReferencedUTXOEntries for loop break condition (#1723)
|
|
||||||
* Fix overflow when checking coinbase maturity and don't ban peers that send transactions with immature spend (#1722)
|
|
||||||
|
|
||||||
Kaspad v0.10.1 - 2021-05-11
|
|
||||||
===========================
|
|
||||||
* Calculate virtual's acceptance data and multiset after importing a new pruning point (#1700)
|
|
||||||
|
|
||||||
Kaspad v0.10.0 - 2021-04-26
|
|
||||||
===========================
|
|
||||||
Major changes include:
|
|
||||||
* Implementing a signature hashing scheme similar to BIP-143
|
|
||||||
* Replacing HASH160 with BLAKE2B
|
|
||||||
* Replacing ECMH with MuHash
|
|
||||||
* Removing RIPEMD160 and SHA1 from the codebase entirely
|
|
||||||
* Making P2PKH transactions non-standard
|
|
||||||
* Vastly enhancing the CLI wallet
|
|
||||||
* Restructuring kaspad's app/home directory
|
|
||||||
* Modifying block and transaction types in the RPC to be easier to consume clientside
|
|
||||||
|
|
||||||
A partial list of the more-important commits is as follows:
|
|
||||||
* Fix data race in GetBlockChildren (#1579)
|
|
||||||
* Remove payload hash (#1583)
|
|
||||||
* Add the mempool size to getInfo RPC command (#1584)
|
|
||||||
* Change the difficulty to be calculated based on the same block instead of its selected parent (#1591)
|
|
||||||
* Adjust the difficulty in the first difficultyAdjustmentWindowSize blocks (#1592)
|
|
||||||
* Adding DAA score (#1596)
|
|
||||||
* Use DAA score where needed (#1602)
|
|
||||||
* Remove the Services field from NetAddress. (#1610)
|
|
||||||
* Fix getBlocks to not add the anticone when some blocks were filtered by GetHashesBetween (#1611)
|
|
||||||
* Restructure the default ~/.kaspad directory layout (#1613)
|
|
||||||
* Replace the HomeDir flag with a AppDir flag (#1615)
|
|
||||||
* Implement BIP-143-like sighash (#1598)
|
|
||||||
* Change --datadir to --appdir and remove symmetrical connection in stability tests (#1617)
|
|
||||||
* Use BLAKE2B instead of HASH160, and get rid of any usage of RIPEMD160 and SHA1 (#1618)
|
|
||||||
* Replace ECMH with Muhash (#1624)
|
|
||||||
* Add support for multiple staging areas (#1633)
|
|
||||||
* Make sure the ghostdagDataStore cache is at least DifficultyAdjustmentBlockWindow sized (#1635)
|
|
||||||
* Resolve each block status in it's own staging area (#1634)
|
|
||||||
* Add mass limit to mempool (#1627)
|
|
||||||
* In RPC, use RPCTransactions and RPCBlocks instead of TransactionMessages and BlockMessages (#1609)
|
|
||||||
* Use go-secp256k1 v0.0.5 (#1640)
|
|
||||||
* Add a show-address subcommand to kaspawallet (#1653)
|
|
||||||
* Replace p2pkh with p2pk (#1650)
|
|
||||||
* Implement importing private keys into the wallet (#1655)
|
|
||||||
* Add dump unencrypted data sub command to the wallet (#1661)
|
|
||||||
* Add ECDSA support (#1657)
|
|
||||||
* Add OpCheckMultiSigECDSA (#1663)
|
|
||||||
* Add ECDSA support to the wallet (#1664)
|
|
||||||
* Make moving the pruning point faster (#1660)
|
|
||||||
* Implement new mechanism for updating UTXO Diffs (#1671)
|
|
||||||
|
|
||||||
Kaspad v0.9.2 - 2021-03-31
|
|
||||||
===========================
|
|
||||||
* Increase the route capacity of InvTransaction messages. (#1603) (#1637)
|
|
||||||
|
|
||||||
Kaspad v0.9.1 - 2021-03-14
|
|
||||||
===========================
|
|
||||||
* Testnet network reset
|
|
||||||
|
|
||||||
Kaspad v0.9.0 - 2021-03-04
|
Kaspad v0.9.0 - 2021-03-04
|
||||||
===========================
|
===========================
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user