Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] publish block info for thirdpart partner #667

Merged
merged 2 commits into from
Oct 30, 2019
Merged

[R4R] publish block info for thirdpart partner #667

merged 2 commits into from
Oct 30, 2019

Conversation

unclezoro
Copy link
Collaborator

@unclezoro unclezoro commented Sep 17, 2019

Description

resolve #668
Third part requires some extra info and more common info(just like other chain) to audit.

So we add a new topic to publish more block info.

related pr bnb-chain/bnc-cosmos-sdk#167

Rationale

Here is the schema

blockdata.json.zip

Notice that the metrics changed: PublishBlockTimeMs is not more the total time, rename to PublishTotalTimeMs.

Notice: Account have an new field: sequence , all downstream service need update the schema @cpzhao @erhenglu @fletcher142

Example

{
    "ChainID":"bnbchain-1000",
    "CryptoBlock":{
        "BlockHash":"febcb38e6f73a6e8a9a25edd34af1a1243d262cf552fe5b6d8e8d5e56151db47",
        "ParentHash":"0f09bcca609ecbf5c5ad448f7cc1c0e8f4cb7d350383dfac21f5854e2960304b",
        "BlockHeight":615,
        "Timestamp":"2019-09-17T06:36:47.998467Z",
        "TxTotal":29,
        "BlockMeta":{
            "LastCommitHash":"b08199aee98218bcf6b2df027df324d2cf1a00c8d34d64831266edb5f7ea972d",
            "DataHash":"28ae673938db1acc616e0549682648f47e60419ebb87d7f707c98f36cc66ee94",
            "ValidatorsHash":"df37cb39c9cfd4bdd65853e79e329938ecb5c968f2bf2cee643cabab0c8c073d",
            "NextValidatorsHash":"df37cb39c9cfd4bdd65853e79e329938ecb5c968f2bf2cee643cabab0c8c073d",
            "ConsensusHash":"294d8fbd0b94b767a7eba9840f299a3586da7fe6b5dead3b7eecba193c400f93",
            "AppHash":"28fe85c8ee8f0f89b152f55837182bb6f4f1fe89ac276712b509a6d9ef335545",
            "LastResultsHash":"",
            "EvidenceHash":"",
            "ProposerAddress":"bca132gd9ucywlg5n0fpp7grjfcwc3pymfpw3y0ncc"
        },
        "Transactions":[
            {
                "TxHash":"9FF02C6EA789C1CC77E87CA32D570C658C70D2BCC3FC9F088BE979650D7BD520",
                "Fee":"37500BNB",
                "Timestamp":"2019-09-17T06:36:47.998467Z",
                "Inputs":[
                    {
                        "Address":"bnb1hxg5aml7wgvzspqhdxx6xvl8z9hwaw8ndn6nwa",
                        "Coins":null
                    }
                ],
                "Outputs":null,
                "BnbTransaction":{
                    "Source":0,
                    "TxType":"depositHTLT",
                    "TxAsset":"",
                    "OrderId":"",
                    "Code":0,
                    "Data":"{"from":"bnb1hxg5aml7wgvzspqhdxx6xvl8z9hwaw8ndn6nwa","amount":[{"denom":"ETH-806","amount":10000}],"swap_id":"a67ed223cea923710bbcf9f171548b3d378342c5a5b129831a537bb23d1adb51"}"
                }
            }
        ]
    }
}

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

Preflight checks

  • build passed (make build)
  • tests passed (make test)
    Race test-case in app/app_test package is failed. Even in master it fails, @xiangdotli @rickyyangz know about this. won't fix in thsi pr
  • integration tests passed (make integration_test)
  • manual transaction test passed (cli invoke)

Already reviewed by

...

Related issues

resolve #668

@unclezoro unclezoro changed the title [WIP]add cipher [WIP]publish block info for third part Sep 17, 2019
@unclezoro unclezoro changed the title [WIP]publish block info for third part [WIP]publish block info for thirdpart partner Sep 17, 2019
Gopkg.lock Outdated
@@ -499,6 +507,14 @@
revision = "9a47f48565a795472d43519dd49aac781f3034fb"
version = "v1.6.0"

[[projects]]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can ignore deadlock and goid depnendency, I will reorg Gopkg.lock and Gopkg.toml before merge.

@unclezoro unclezoro changed the title [WIP]publish block info for thirdpart partner [R4R] publish block info for thirdpart partner Sep 18, 2019
@unclezoro unclezoro requested review from ackratos, abelliumnt, rickyyangz and yutianwu and removed request for ackratos September 18, 2019 07:07
@@ -0,0 +1,37 @@
package tx
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a pool.go file in cosmos. Why I choose put here: 1. cosmos-sdk won't use this file. 2. the pool.go in cosmos use sync.map, which is not suit for this scene

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name pool is a little weird, tx.pool looks like a tx mempool, How about name it TxResults and put it under app/pub package

Copy link
Collaborator Author

@unclezoro unclezoro Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I move it into app/pub package, but still name it as pool.go, for now it only store txResult, but it can store other things in the future.

publishBlock = {{ .PublicationConfig.PublishBlock }}
blockTopic = "{{ .PublicationConfig.BlockTopic }}"
blockKafka = "{{ .PublicationConfig.BlockKafka }}"

# Global setting
publicationChannelSize = "{{ .PublicationConfig.PublicationChannelSize }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you help me remove the double-quote? :) Its my mistake

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Gopkg.toml Outdated
@@ -42,7 +42,7 @@
[[constraint]]
name = "github.com/cosmos/cosmos-sdk"
source = "github.com/binance-chain/bnc-cosmos-sdk"
version = "=v0.25.0-binance.19"
branch = "blockhash"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, after cosmos release or merged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can change back to develop branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed back to develop

app/pub/helpers.go Show resolved Hide resolved
app/pub/helpers.go Outdated Show resolved Hide resolved
@@ -44,11 +47,12 @@ func (this msgType) String() string {
// figure out which version of writer schema to use.
// This allows consumers be deployed independently (in advance) with publisher
var latestSchemaVersions = map[msgType]int{
accountsTpe: 0,
accountsTpe: 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please notice me and kaiqiang when this is going to deploy

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

app/pub/schema_test.go Outdated Show resolved Hide resolved
app/pub/schemas.go Show resolved Hide resolved
app/pub/helpers.go Outdated Show resolved Hide resolved
Logger.Error("tx contains no messages", "hash", txhash)
return true
}
// Notice: if support multi message in one transaction in future, this part need change
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’d better Make a todo comment with issue number.

inputs := []Input{{Address: msg.GetSigners()[0].String()}}

switch msg := msg.(type) {
case orderPkg.NewOrderMsg:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest if time allowed we add interface to each message which is more maintainable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need for the abstraction. Cipher trace's requirement is special, no need to change the basic interface of Msg for them. txAsset, inputs, outputs is more like bitcoin concept, most message do not have such interface.

@@ -32,6 +32,7 @@ type KafkaMarketDataPublisher struct {
transfersCodec *goavro.Codec
blockCodec *goavro.Codec

failFast bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for which nodes we enable this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we won't enable this, but cypher trace will.

@unclezoro unclezoro changed the base branch from master to develop October 23, 2019 09:51
@@ -463,15 +463,18 @@ func (app *BinanceChain) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
// Implements ABCI
func (app *BinanceChain) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
res = app.BaseApp.DeliverTx(txBytes)
txHash := cmn.HexBytes(tmhash.Sum(txBytes)).String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txHash have been calculated for serveral times in deliverTx. We should pass the txHash to inner functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really an issue that bothers us long, since it is not the purpose of this pr, let us do it in . #683

app/pub/msgs.go Outdated
Timestamp string
TxTotal int64

BnbBlockMeta BlockMeta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use bnb, use NativeToken instead

Copy link
Collaborator Author

@unclezoro unclezoro Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a requirement from cipher trace: They will handle multi chain message, they want to us to distinguish common block message and bnb specified message. As you see, CryptoBlock is actually totall metadata of block, while BnbBlockMeta only hold the metadata only binance chain have.

app/pub/msgs.go Outdated
Inputs []Input
Outputs []Output

BnbTransaction BnbTransaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's BnbTransaction mean

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message only transaction of Binance chain have.

# whether the kafka open SASL_PLAINTEXT auth
auth = {{ .PublicationConfig.Auth }}
kafkaUserName = "{{ .PublicationConfig.KafkaUserName }}"
kafkaPassword = "{{ .PublicationConfig.KafkaPassword }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it secure to put username and password in the config file

Copy link
Collaborator Author

@unclezoro unclezoro Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We won't use this. Actually there are some offline method can solve this, decipher the password and start the node, then encrypt the password. If going to support encryption of password, have to store decryption material in some hardware or cloud service, more requirement for the hardware. Just leave it to cipher trace.

@unclezoro unclezoro force-pushed the cipher branch 3 times, most recently from 5177b28 to aaee617 Compare October 28, 2019 11:17
gofmt & goimports

update dependent

add auth to cipher

publish fail fast

fix review suggestion

add change log

fix import

change back to develop branch
@abelliumnt abelliumnt merged commit 59a431f into develop Oct 30, 2019
@unclezoro unclezoro deleted the cipher branch May 10, 2022 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants