Skip to content

Commit

Permalink
Merge pull request #118 from commerceblock/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
Nikos Kostoulas authored Oct 31, 2019
2 parents 33a20b1 + 0beae02 commit 89f7e42
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
9 changes: 7 additions & 2 deletions attestation/attestclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,13 @@ func (w *AttestClient) bumpAttestationFees(msgTx *wire.MsgTx, isFeeBumped bool)
// Calculate the size of a signed transaction by summing the unsigned tx size
// and the redeem script size and estimated signature size of the scriptsig
func calcSignedTxSize(unsignedTxSize int, scriptSize int, numOfSigs int, numOfInputs int) int {
return unsignedTxSize + /*script size byte*/ (1+scriptSize+
/*00 scriptsig byte*/ 1+numOfSigs*( /*sig size byte*/ 1+72))*numOfInputs
var pushDataSize int
if pushDataSize = 0; scriptSize > 75 {
pushDataSize = 1
}
scriptSigSize := /*size byte*/ 1 + pushDataSize + scriptSize + /*00 byte*/ 1 + numOfSigs*( /*size byte*/ 1+72)
scriptSigSizeSize := wire.VarIntSerializeSize(uint64(scriptSigSize)) - 1 // unsignedTxSize includes 1 byte already
return unsignedTxSize + (scriptSigSize+scriptSigSizeSize)*numOfInputs
}

// Calculate the actual fee of an unsigned transaction by taking into consideration
Expand Down
8 changes: 4 additions & 4 deletions attestation/attestclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ func TestAttestClient_feeCalculation(t *testing.T) {
script2 := "52210325bf82856a8fdcc7a2c08a933343d2c6332c4c252974d6b09b6232ea4080462621028ed149d77203c79d7524048689a80cc98f27e3427f2edaec52eae1f630978e08210254a548b59741ba35bfb085744373a8e10b1cf96e71f53356d7d97f807258d38c53ae"
scriptSize2 := len(script2) / 2
_, numOfSigs2 := crypto.ParseRedeemScript(script2)
assert.Equal(t, 336, calcSignedTxSize(unsignedTxSize, scriptSize2, numOfSigs2, 1))
assert.Equal(t, int64(3360), calcSignedTxFee(feePerByte, unsignedTxSize, scriptSize2, numOfSigs2, 1))
assert.Equal(t, 339, calcSignedTxSize(unsignedTxSize, scriptSize2, numOfSigs2, 1))
assert.Equal(t, int64(3390), calcSignedTxFee(feePerByte, unsignedTxSize, scriptSize2, numOfSigs2, 1))

assert.Equal(t, 842, calcSignedTxSize(unsignedTxSize, scriptSize2, numOfSigs2, 3))
assert.Equal(t, int64(8420), calcSignedTxFee(feePerByte, unsignedTxSize, scriptSize2, numOfSigs2, 3))
assert.Equal(t, 851, calcSignedTxSize(unsignedTxSize, scriptSize2, numOfSigs2, 3))
assert.Equal(t, int64(8510), calcSignedTxFee(feePerByte, unsignedTxSize, scriptSize2, numOfSigs2, 3))
}
6 changes: 4 additions & 2 deletions attestation/attestservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
// waiting time schedules
const (
// fixed waiting time between states
ATimeFixed = 5 * time.Second
ATimeFixed = 100 * time.Millisecond

// waiting time for sigs to arrive from multisig nodes
ATimeSigs = 1 * time.Minute
Expand Down Expand Up @@ -159,7 +159,7 @@ func (s *AttestService) Run() {

// for testing - overwrite delay
if s.isRegtest {
attestDelay = 10 * time.Second
attestDelay = 5 * time.Second
}

log.Printf("********** sleeping for: %s ...\n", attestDelay.String())
Expand Down Expand Up @@ -406,6 +406,7 @@ func (s *AttestService) doStateNewAttestation() {
txPreImageBytes = append(txPreImageBytes, txBytesBuffer.Bytes())
}
s.signer.SendTxPreImages(txPreImageBytes)
s.signer.ReSubscribe()

s.state = AStateSignAttestation // update attestation state
attestDelay = ATimeSigs // add sigs waiting time
Expand Down Expand Up @@ -561,6 +562,7 @@ func (s *AttestService) doStateHandleUnconfirmed() {
txPreImageBytes = append(txPreImageBytes, txBytesBuffer.Bytes())
}
s.signer.SendTxPreImages(txPreImageBytes)
s.signer.ReSubscribe()

s.state = AStateSignAttestation // update attestation state
attestDelay = ATimeSigs // add sigs waiting time
Expand Down
2 changes: 1 addition & 1 deletion db/db_mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (
// Method to connect to mongo database through config
func dbConnect(ctx context.Context, dbConnectivity config.DbConfig) (*mongo.Database, error) {
// get this from config
uri := fmt.Sprintf(`mongodb://%s:%s@%s:%s/%s`,
uri := fmt.Sprintf(`mongodb://%s:%s@%s:%s/%s?connect=direct`,
dbConnectivity.User,
dbConnectivity.Password,
dbConnectivity.Host,
Expand Down

0 comments on commit 89f7e42

Please sign in to comment.