Skip to content

Commit

Permalink
chore: fixes after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmkowalski committed Feb 21, 2024
1 parent df8e28c commit 2908a15
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 32 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
with:
version: ${{ github.ref_name }}
os: linux
go_main_file: cmd/server/main.go
cgo_enabled: true
release_binaries: false
secrets:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /go/src/github.com/bitcoin-sv/spv-wallet
COPY . ./

# Build binary
RUN GOOS=linux go build -o spvwallet cmd/server/main.go
RUN GOOS=linux go build -o spvwallet cmd/main.go

# Get runtime image
FROM registry.access.redhat.com/ubi9-minimal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ go run ./cmd/main.go -C /my/config.json

#### Environment variables

To override any config variable with ENV, use the "SPV\_" prefix with mapstructure annotation path with "_" as a delimiter in all uppercase. Example:
To override any config variable with ENV, use the "SPVWALLET\_" prefix with mapstructure annotation path with "_" as a delimiter in all uppercase. Example:

Let's take this fragment of AppConfig from `config.example.yaml`:

Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
return
}

// Try to ping the block header service if enabled
// Try to ping the Block Headers Service if enabled
appConfig.CheckBlockHeaderService(context.Background(), services.Logger)

// @mrz New Relic is ready at this point
Expand Down
2 changes: 1 addition & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ notifications:
paymail:
beef:
block_headers_service_auth_token: mQZQ6WmxURxWz5ch
# url to block header service, used for merkle root verification
# url to Block Headers Service, used for merkle root verification
block_headers_service_url: http://localhost:8080/api/v1/chain/merkleroot/verify
use_beef: false
# set is as a default sender paymail if account does not have one
Expand Down
24 changes: 12 additions & 12 deletions config/check_block_header_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ const pastMerkleRootsJSON = `[
]`

const (
pleaseCheck = "Please check Block Header Service configuration and service status."
appWillContinue = "Application will continue to operate but cannot receive transactions until Block Header Service is online."
blockHeaderServiceIsOfflineWarning = "Unable to connect to Block Header Service service at startup. " + appWillContinue + " " + pleaseCheck
unexpectedResponse = "Unexpected response from Block Header Service service. " + pleaseCheck
blockHeaderServiceIsNotReadyWarning = "Block Header Service is responding but is not ready to verify transactions. " + appWillContinue
pleaseCheck = "Please check Block Headers Service configuration and service status."
appWillContinue = "Application will continue to operate but cannot receive transactions until Block Headers Service is online."
blockHeaderServiceIsOfflineWarning = "Unable to connect to Block Headers Service service at startup. " + appWillContinue + " " + pleaseCheck
unexpectedResponse = "Unexpected response from Block Headers Service service. " + pleaseCheck
blockHeaderServiceIsNotReadyWarning = "Block Headers Service is responding but is not ready to verify transactions. " + appWillContinue
)

// CheckBlockHeaderService tries to make a request to the Block Header Service to check if it is online and ready to verify transactions.
// CheckBlockHeaderService tries to make a request to the Block Headers Service to check if it is online and ready to verify transactions.
// AppConfig should be validated before calling this method.
// This method returns nothing, instead it logs either an error or a warning based on the state of the Block Header Service.
// This method returns nothing, instead it logs either an error or a warning based on the state of the Block Headers Service.
func (config *AppConfig) CheckBlockHeaderService(ctx context.Context, logger *zerolog.Logger) {
if !config.BlockHeaderServiceEnabled() {
// this method works only with Beef/Block Header Service enabled
// this method works only with Beef/Block Headers Service enabled
return
}
b := config.Paymail.Beef

logger.Info().Msg("checking Block Header Service")
logger.Info().Msg("checking Block Headers Service")

timedCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

req, err := http.NewRequestWithContext(timedCtx, "POST", b.BlockHeaderServiceHeaderValidationURL, bytes.NewBufferString(pastMerkleRootsJSON))
if err != nil {
logger.Error().Err(err).Msg("error checking Block Header Service - failed to create request")
logger.Error().Err(err).Msg("error checking Block Headers Service - failed to create request")
return
}

Expand Down Expand Up @@ -79,10 +79,10 @@ func (config *AppConfig) CheckBlockHeaderService(ctx context.Context, logger *ze
return
}

logger.Info().Msg("Block Header Service is ready to verify transactions.")
logger.Info().Msg("Block Headers Service is ready to verify transactions.")
}

// BlockHeaderServiceEnabled returns true if the Block Header Service is enabled in the AppConfig
// BlockHeaderServiceEnabled returns true if the Block Headers Service is enabled in the AppConfig
func (config *AppConfig) BlockHeaderServiceEnabled() bool {
return config.Paymail != nil && config.Paymail.Beef.enabled()
}
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ type PaymailConfig struct {
SenderValidationEnabled bool `json:"sender_validation_enabled" mapstructure:"sender_validation_enabled"`
}

// BeefConfig consists of components required to use beef, e.g. Block Header Service for merkle roots validation
// BeefConfig consists of components required to use beef, e.g. Block Headers Service for merkle roots validation
type BeefConfig struct {
// UseBeef is a flag for enabling BEEF transactions format.
UseBeef bool `json:"use_beef" mapstructure:"use_beef"`
// BlockHeaderServiceHeaderValidationURL is the URL for merkle roots validation in Block Header Service.
// BlockHeaderServiceHeaderValidationURL is the URL for merkle roots validation in Block Headers Service.
BlockHeaderServiceHeaderValidationURL string `json:"block_header_service_url" mapstructure:"block_header_service_url"`
// BlockHeaderServiceAuthToken is the authentication token for validating merkle roots in Block Header Service.
// BlockHeaderServiceAuthToken is the authentication token for validating merkle roots in Block Headers Service.
BlockHeaderServiceAuthToken string `json:"block_header_service_auth_token" mapstructure:"block_header_service_auth_token"`
}

Expand Down
2 changes: 1 addition & 1 deletion config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestLoadConfig(t *testing.T) {

// when
// IMPORTANT! If you need to change the name of this variable, it means you're
// making backwards incompatible changes. Please inform all SPV adoptors and
// making backwards incompatible changes. Please inform all SPV Wallet adoptors and
// update your configs on all servers and scripts.
os.Setenv(EnvPrefix+"_CONFIG_FILE", anotherPath)
_, err := Load(defaultLogger)
Expand Down
2 changes: 1 addition & 1 deletion engine/chainstate/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func WithBroadcastClient(client broadcast.Client) ClientOps {
}
}

// WithConnectionToBlockHeaderService will set block headers service API settings.
// WithConnectionToBlockHeaderService will set Block Headers Service API settings.
func WithConnectionToBlockHeaderService(url, authToken string) ClientOps {
return func(c *clientOptions) {
c.config.blockHedersServiceClient = newBlockHeaderServiceClientProvider(url, authToken)
Expand Down
4 changes: 2 additions & 2 deletions engine/chainstate/merkle_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
)

// VerifyMerkleRoots will try to verify merkle roots with all available providers
// When no error is returned, it means that the block headers service client responded with state: Confirmed or UnableToVerify
// When no error is returned, it means that the Block Headers Service client responded with state: Confirmed or UnableToVerify
func (c *Client) VerifyMerkleRoots(ctx context.Context, merkleRoots []MerkleRootConfirmationRequestItem) error {
pc := c.options.config.blockHedersServiceClient
if pc == nil {
c.options.logger.Warn().Msg("VerifyMerkleRoots is called even though no block headers service client is configured; this likely indicates that the paymail capabilities have been cached.")
c.options.logger.Warn().Msg("VerifyMerkleRoots is called even though no Block Headers Service client is configured; this likely indicates that the paymail capabilities have been cached.")
return errors.New("no block headers service client found")
}
merkleRootsRes, err := pc.verifyMerkleRoots(ctx, c.options.logger, merkleRoots)
Expand Down
8 changes: 4 additions & 4 deletions engine/chainstate/merkle_root_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ func (p *blockHeadersServiceClientProvider) verifyMerkleRoots(
}()
}
if err != nil {
return nil, _fmtAndLogError(err, logger, "Error occurred while sending request to the Block Headers Service service.")
return nil, _fmtAndLogError(err, logger, "Error occurred while sending request to the Block Headers Service.")
}

if res.StatusCode != 200 {
return nil, _fmtAndLogError(_statusError(res.StatusCode), logger, "Received unexpected status code from Block Headers Service service.")
return nil, _fmtAndLogError(_statusError(res.StatusCode), logger, "Received unexpected status code from Block Headers Service.")
}

// Parse response body.
var merkleRootsRes MerkleRootsConfirmationsResponse
err = json.NewDecoder(res.Body).Decode(&merkleRootsRes)
if err != nil {
return nil, _fmtAndLogError(err, logger, "Error occurred while parsing response from the Block Headers Service service.")
return nil, _fmtAndLogError(err, logger, "Error occurred while parsing response from the Block Headers Service.")
}

return &merkleRootsRes, nil
Expand All @@ -105,5 +105,5 @@ func _fmtAndLogError(err error, logger *zerolog.Logger, message string) error {
}

func _statusError(statusCode int) error {
return fmt.Errorf("block headers service client returned status code %d - check Block Headers Service configuration and service status", statusCode)
return fmt.Errorf("Block Headers Service client returned status code %d - check Block Headers Service configuration and status", statusCode)
}
6 changes: 3 additions & 3 deletions engine/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,13 @@ func WithPaymailSupport(domains []string, defaultFromPaymail string, domainValid
}

// WithPaymailBeefSupport will enable Paymail BEEF format support (as a server) and create a Block Headers Service client for Merkle Roots verification.
func WithPaymailBeefSupport(bhsURL, bhsAuthToken string) ClientOps {
func WithPaymailBeefSupport(blockHeadersServiceURL, blockHeadersServiceAuthToken string) ClientOps {
return func(c *clientOptions) {
_, err := url.ParseRequestURI(bhsURL)
_, err := url.ParseRequestURI(blockHeadersServiceURL)
if err != nil {
panic(err)
}
c.chainstate.options = append(c.chainstate.options, chainstate.WithConnectionToBlockHeaderService(bhsURL, bhsAuthToken))
c.chainstate.options = append(c.chainstate.options, chainstate.WithConnectionToBlockHeaderService(blockHeadersServiceURL, blockHeadersServiceAuthToken))
c.paymail.serverConfig.options = append(c.paymail.serverConfig.options, server.WithBeefCapabilities())
}
}
Expand Down
2 changes: 1 addition & 1 deletion logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetDefaultLogger() *zerolog.Logger {
logger := ecszerolog.New(os.Stdout, ecszerolog.Level(zerolog.DebugLevel)).
With().
Caller().
Str("application", "spv-default").
Str("application", "spv-wallet-default").
Logger()

return &logger
Expand Down

0 comments on commit 2908a15

Please sign in to comment.