It is grammatically correct, except that you probably need a full stop before but. At the very least you need a semicolon there. Was there anything specific that you thought might be ungrammatical about your sentence? The italicised part is not necessary (but it is perfectly fine).
It is not, however, correct in formal logic.
If it weren't raining, there wouldn't be a puddle. But there is a puddle; therefore it is raining.
In formal logic, that conclusion is invalid, because one cannot draw any conclusions based on the consequence; only from the antecedent can one draw conclusions, and only if it is true (then the consequent must also be true). Purely as an illustration: if this example were in the real world, there could be a puddle but without any raining (it could be a garden hose).
However, there is in real language a very strong implication that antecedent and consequence correlate. So your implication is perfectly fine in a normal context (outside formal logic).
In general, a statement can be syntactically correct but logically incorrect, or even nonsense. Consider Chomsky's famous sentence:
Colorless green ideas sleep furiously. [syntactically perfect, but nonsense]
*Furiously sleep ideas green colorless. [syntactically flawed, and equally nonsensical]