gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
929 stars 264 forks source link

serious bug: message version `Legacy` and `0` is not mapped to `0` and `1` #180

Closed GoudanWoo closed 8 months ago

GoudanWoo commented 8 months ago

You defined LegacyMessage as 0 and VersionedMessage as 1.

https://github.com/gagliardetto/solana-go/blob/a8900f8a1f2cddbd2dc09c81d036eeb956274ac8/message.go#L84-L87

But according to the docs, LegacyMessage is nil and VersionedMessage is 0.

legacy demo

2PrNuegoDfneMGVAf1akbNPo1omkpNX7yZxYhwH42AWYD78wA6c3ZE5wYdRtL6fAMwjCpAjFVsviubFiWDSNhU3Y

image

rpc will return:

{
    "jsonrpc": "2.0",
    "result": {
        "blockTime": 1710904462,
        "slot": 255260375,
        "transaction": {
            "signatures": [
                "2PrNuegoDfneMGVAf1akbNPo1omkpNX7yZxYhwH42AWYD78wA6c3ZE5wYdRtL6fAMwjCpAjFVsviubFiWDSNhU3Y"
            ]
        }
    },
    "id": "24c1f13e-93f0-4e4b-9d13-ea84c8b65ed5"
}

you can see that .result.version is undefined/nil.

and GetTransaction return:

   ├─ Signatures[len=1]
   │    └─ 2PrNuegoDfneMGVAf1akbNPo1omkpNX7yZxYhwH42AWYD78wA6c3ZE5wYdRtL6fAMwjCpAjFVsviubFiWDSNhU3Y
   ├─ Message
   │    ├─ Version: legacy
   │    ├─ RecentBlockhash: GdR4nt4SYzx5SwaTNMAsCAqesMQnswaxMFNNBiJnYSVh
   │    ├─ AccountKeys[len=3]
   │    │    ├─ 888jyPHuucwtYFepqQY7F55xXeBP4P3pp8QC8Awai888
   │    │    ├─ 5VCwKtCXgCJ6kit5FybXjvriW3xELsFDhYrPSqtJNmcD
   │    │    └─ 11111111111111111111111111111111
   │    └─ Header
   │       ├─ NumRequiredSignatures: 1
   │       ├─ NumReadonlySignedAccounts: 0
   │       └─ NumReadonlyUnsignedAccounts: 1
   └─ Instructions[len=1]
      └─ Program: System 11111111111111111111111111111111
         └─ Instruction: Transfer
            ├─ Params
            │    └─ Lamports: (uint64) 0
            └─ Accounts
               ├─   Funding: 888jyPHuucwtYFepqQY7F55xXeBP4P3pp8QC8Awai888 [WRITE, SIGN]
               └─ Recipient: 5VCwKtCXgCJ6kit5FybXjvriW3xELsFDhYrPSqtJNmcD [WRITE]

versioned demo

Gb3VpwEi4s6ikQ32iwcaJUd8zk8NqEYARe8QvsDNq554Bsb8X7RC1gPGEtq6iURwiUAEXzAngqU7vh2Dch3NUzf

image

rpc will return:

{
    "jsonrpc": "2.0",
    "result": {
        "blockTime": 1711158614,
        "slot": 255862259,
        "transaction": {
            "signatures": [
                "Gb3VpwEi4s6ikQ32iwcaJUd8zk8NqEYARe8QvsDNq554Bsb8X7RC1gPGEtq6iURwiUAEXzAngqU7vh2Dch3NUzf"
            ]
        },
        "version": 0
    },
    "id": "24c1f13e-93f0-4e4b-9d13-ea84c8b65ed5"
}

you can see that .result.version is 0.

and GetTransaction return:

   ├─ Signatures[len=1]
   │    └─ Gb3VpwEi4s6ikQ32iwcaJUd8zk8NqEYARe8QvsDNq554Bsb8X7RC1gPGEtq6iURwiUAEXzAngqU7vh2Dch3NUzf
   ├─ Message
   │    ├─ Version: legacy
   │    ├─ RecentBlockhash: 9NuHgH9m4mAVq9sYyBJAnGXPuaN8Qb6wwEXwcDzm1itF
   │    ├─ AccountKeys[len=24]
   │    │    └─ AccountMetaList: address table lookup not found for account: 2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17
   │    └─ Header
   │       ├─ NumRequiredSignatures: 1
   │       ├─ NumReadonlySignedAccounts: 0
   │       └─ NumReadonlyUnsignedAccounts: 8
   └─ Instructions[len=6]
      └─ cannot ResolveInstructionAccounts: address table lookup not found for account: 2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17

so all unmarshal and marshal of transaction message may have bugs.

GoudanWoo commented 8 months ago

if I try to call rpc with option encoding: base64, it will return:

legacy demo

{
    "jsonrpc": "2.0",
    "result": {
        "blockTime": 1710904462,
        "slot": 255260375,
        "transaction": [
            "...",
            "base64"
        ],
        "version": "legacy"
    },
    "id": "24c1f13e-93f0-4e4b-9d13-ea84c8b65ed5"
}

versioned demo

{
    "jsonrpc": "2.0",
    "result": {
        "blockTime": 1711158614,
        "slot": 255862259,
        "transaction": [
            "...",
            "base64"
        ],
        "version": 0
    },
    "id": "24c1f13e-93f0-4e4b-9d13-ea84c8b65ed5"
}
GoudanWoo commented 8 months ago

I found that

https://github.com/gagliardetto/solana-go/blob/a8900f8a1f2cddbd2dc09c81d036eeb956274ac8/rpc/transaction_version.go#L5-L10

so it is my misunderstanding.